473,395 Members | 2,443 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

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,NUM_LEADS];
/* snip */
for( unsigned iLead = 0; iLead < NUM_LEADS; iLead++ ) {
short* piData = g_data + BUFFER_SAMPLES * iLead + BLOCK_SAMPLES *
g_nValid100msBlocks;
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
ArrayIndexOutOfBoundsException?
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
ArrayIndexOutOfBoundsException?
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 1201
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.microsoft.com> wrote in message
news:nT**************@TK2MSFTNGXA02.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
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...
16
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...
6
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...
18
by: Vasileios Zografos | last post by:
Hello, can anyone please tell me if there is any difference between the two: double Array1; and
2
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...
23
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...
5
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...
57
by: buuuuuum | last post by:
why array can't be assigned, like structs?
0
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
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...
0
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...
0
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...

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.