473,898 Members | 2,481 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Managed C++ silently ignores my array assignment

I am accustomed to using a pointer to traverse an array in native C++. Here
I am trying to copy a slice of a native 2-D array into a managed 2-D array
to make it accessible by C#. But piData isn't incremented and no value is
stored in m_aaSamples. Anyone know why?

m_aaSamples = new System::UInt16[BLOCK_SAMPLES,N UM_LEADS];
/* snip */
for( unsigned iLead = 0; iLead < NUM_LEADS; iLead++ ) {
short* piData = g_data + BUFFER_SAMPLES * iLead + BLOCK_SAMPLES *
g_nValid100msBl ocks;
for( unsigned iSample = 0; iSample < BLOCK_SAMPLES; iSample++ ) {
m_aaSamples[iSample,iLead] = *(piData++);
}
}
Optimization is OFF. Disassembly with my best guess at what is happening:

(apparently esi is iLead and ebx is iSample)

m_aaSamples[iSample,iLead] = *(piData++);
000000c8 mov eax,ebx
000000ca mov edx,esi
000000cc mov ecx,dword ptr ds:[01B32608h] base of m_aaSamples
array descriptor, I think
000000d2 sub eax,dword ptr [ecx+10h] m_aaSamples lower
bound dim #0 I think
000000d5 cmp eax,dword ptr [ecx+8] m_aaSamples size
dim #0 I think
000000d8 jb 000000E1 always
hits, index bounds checking?
000000da xor ecx,ecx
ecx <= 0
000000dc call 75D5CF18 throw
ArrayIndexOutOf BoundsException ?
000000e1 sub edx,dword ptr [ecx+14h] m_aaSamples lower
bound dim#1?
000000e4 cmp edx,dword ptr [ecx+0Ch] m_aaSamples lower
bound dim#1?
000000e7 jb 000000F0 always
hits, index bounds checking?
000000e9 xor ecx,ecx
ecx <= 0
000000eb call 75D5CF18 throw
ArrayIndexOutOf BoundsException ?
000000f0 imul eax,dword ptr [ecx+0Ch] offset <= row *
COLUMNS
000000f4 add eax,edx
+ col
000000f6 mov edx,dword ptr [ebp-10h] read *piData?
000000f9 mov word ptr [ecx+eax*2+18h],dx index into m_aaSamples
based on offset and sizeof (short)

I cannot for the life of me figure out what happens to the post-increment!
Help!

Jan 19 '06 #1
4 1220
Hi Ben
But piData isn't incremented and no value is
stored in m_aaSamples. Anyone know why?


It appears to be a VC2003 compiler's issue, I performed some tests on my
side, there is no corresponding disassembly code to the pointer's
self-increment operation on the following code:

m_aaSamples[iSample,iLead] = *(piData++);

I suggest you split the piData pointer's self-increment operation into a
self-alone code to workaround this problem:

m_aaSamples[iSample,iLead] = *piData++;
piData++;
Thanks!

Best regards,

Gary Chang
Microsoft Community Support
--------------------
Get Secure! ¡§C www.microsoft.com/security
Register to Access MSDN Managed Newsgroups!
http://support.microsoft.com/default...sdn/nospam.asp
&SD=msdn

This posting is provided "AS IS" with no warranties, and confers no rights.

Jan 20 '06 #2
""Gary Chang[MSFT]"" <v-******@online.m icrosoft.com> wrote in message
news:nT******** ******@TK2MSFTN GXA02.phx.gbl.. .
It appears to be a VC2003 compiler's issue, I performed some tests on my
side, there is no corresponding disassembly code to the pointer's
self-increment operation on the following code:

m_aaSamples[iSample,iLead] = *(piData++);

I suggest you split the piData pointer's self-increment operation into a
self-alone code to workaround this problem:
That idea is theoretically valid as a temporary workaround, but your code is
dangerous:
m_aaSamples[iSample,iLead] = *piData++;
piData++;


Suppose someday Microsoft allows customers to get hotfixes, service packs,
or whatever it takes to get products closer to working as documented. Then
your code will increment piData twice. Maybe that's why Microsoft usually
doesn't let customers download hotfixes? Is it really recommended that
people should become dependent on Microsoft's bugs?

This particular case is lucky though. A safe workaround is possible:

m_aaSamples[iSample,iLead] = *piData;
piData++;

Jan 23 '06 #3
Sorry, Ben, I mistyped my suggested sample code, it should be:

m_aaSamples[iSample,iLead] = *piData;
piData++;
Thanks !

Best regards,

Gary Chang
Microsoft Community Support
--------------------
Get Secure! ¡§C www.microsoft.com/security
Register to Access MSDN Managed Newsgroups!
http://support.microsoft.com/default...sdn/nospam.asp
&SD=msdn

This posting is provided "AS IS" with no warranties, and confers no rights.

Jan 23 '06 #4
Thanks, Norman, actually I mistyped my sample code, it should be no
self-increment operation in the first array assignment code line .(:
Best regards,

Gary Chang
Microsoft Community Support
--------------------
Get Secure! ¡§C www.microsoft.com/security
Register to Access MSDN Managed Newsgroups!
http://support.microsoft.com/default...sdn/nospam.asp
&SD=msdn

This posting is provided "AS IS" with no warranties, and confers no rights.

Jan 23 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

27
51773
by: Trep | last post by:
Hi there! I've been having a lot of difficult trying to figure out a way to convert a terminated char array to a system::string for use in Visual C++ .NET 2003. This is necessary because I have some legcay C code that needs to process a string taken from a textbox, then I need to re-display the string as the textbox->Text. I easily found how to convert from system::string to char but I can't figure out how to go the other way!!
16
14171
by: Ekim | last post by:
hello, I'm allocating a byte-Array in C# with byte byteArray = new byte; Now I want to pass this byte-Array to a managed C++-function by reference, so that I'm able to change the content of the byteArray and afterwards see the changes in C#. (if you wanna know more details: the goal is to write the content of an existing char-array in c++ precisely into the passed byteArray, so that after the function has proceded the content of the...
6
2563
by: Omid Hodjati | last post by:
Hi All, I implemented an encryption algorithm using C#, native C++ and managed C++. Then I measured the CPU time used for executing this algorithm in all implementation. The managed version of C++ was the worst ! It is 20 times slower that the native version and 6 times slower that the C# versio !! Because i wanted to use automatic memory management offered by .Net framework, i used the managaed classes available. e.g. i have used...
18
2276
by: Vasileios Zografos | last post by:
Hello, can anyone please tell me if there is any difference between the two: double Array1; and
2
1705
by: symbol | last post by:
I am having this problem in a managed c++ DLL which mixes managed and unmanaged C/C++ code. I tried to assign value to a struct array nested in another struct. but I can only write to the first element in array, not the others. struct struct2{ int a; int b; };
23
7446
by: sandy | last post by:
I need (okay, I want) to make a dynamic array of my class 'Directory', within my class Directory (Can you already smell disaster?) Each Directory can have subdirectories so I thought to put these in an array. The application compiles but aborts without giving me any useful information. What I suspect is happening is infinite recursion. Each Directory object creates an array of Subdirectories each of which has an array of...
5
2300
by: raylopez99 | last post by:
I need an example of a managed overloaded assignment operator for a reference class, so I can equate two classes A1 and A2, say called ARefClass, in this manner: A1=A2;. For some strange reason my C++.NET 2.0 textbook does not have one. I tried to build one using the format as taught in my regular C++ book, but I keep getting compiler errors. Some errors claim (contrary to my book) that you cannot use a static function, that you must...
57
3297
by: buuuuuum | last post by:
why array can't be assigned, like structs?
0
1369
by: Roshan | last post by:
Hi, I have a managed app which is compiled in VS2005 with platform target "AnyCPU". However when running on a 64 bit platfrom, I notice that when the app tries to access files under C:\Windows\System32, it is being silently redirected to C:\Windows\SysWOW64. Also in task manager, the process has a *32 in front of it indicating that its a 32 bit app, which explains the WOW64 redirection. Is there a way to configure VS2005 so that the...
0
11265
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10859
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10954
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10487
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9662
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
7191
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
6078
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4708
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
3308
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.