Passing multidimensional array to unmanaged C

gtumini

New member
Joined
Mar 3, 2006
Messages
1
Programming Experience
5-10
Hi All,

I have been struggling to find more info about how multidimensional arrays are allocated/structured in memory when passed as argument to a C function:

VB.Net code:
Public Declare Function MyFunction Lib"mydll.dll" (ByRef myArray As Single) As Short
dllRet = MyFunction( myArray(index1,index2)) )

C code :
__declspec( dllexport ) short WINAPI MyFunction( float *myArray)


{
index2Offset = index2Value * maxIndex1Value;
for(index1Value=0; index1Value<maxIndex1Value; index1Value++)


{
myArray[index2Offset + index1Value] = value;


}


}

In VB6 myArray() would be allocated contiguosly as follows:
myArray(0,0)
myArray(1,0)
...
myArray(maxIndex1Value-1,0)
myArray(0,1)
myArray(1,1)
...
myArray(maxIndex1Value-1,1)
...
myArray(0,maxIndex2Value-1)
myArray(1,maxIndex2Value-1)
...
myArray(maxIndex1Value-1,maxIndex2Value-1)

In VB.Net I noticed that myArray(,) is allocated the opposite way:
myArray(0,0)
myArray(0,1)
...
myArray(0,maxIndex2Value-1)
myArray(1,0)
myArray(1,1)
...
myArray(1,maxIndex2Value-1)
...
myArray(maxIndex1Value-1,0)
myArray(maxIndex1Value-1,1)
...
myArray(maxIndex1Value-1,maxIndex2Value-1)

Is this correct? Am I overlooking something here? It seems a pretty big change to me. Does anybody have any insight on this issue?

Thank you.

Giacomo Tumini
 
Back
Top