I’m porting some C++ code to Actionscript 3 and just had a small question I’m confused about.
In one function, one of the parameters is int* myPtr. myPtr is the address of an element of a 2D-Array, &my2DArray[x][y]. x and y are also parameters of the function. I’m just a little bit confused with what is being accessed when the code accesses, for example, myPtr[1]. I think this would be the next element in my2dArray, but I’m not sure if this would be my2DArray[x+1][y] or my2DArray[x][y+1]. Thanks for any help.
Additional info:
my2DArray is created by:
//initPtr is a int*, auxPtr is a int*, as is temp1
initPtr = (unsigned int *)NewPtr(
sizeof(unsigned int) *
X * Y);
}
auxPtr = initPtr ;
for (i = 0; i < X; i++) {
temp1 = auxPtr + i * Y;
my2DArray[i] = (short *)temp1;
}
unsigned char* NewPtr(
int size)
{
return ((unsigned char*)calloc(size, sizeof(unsigned char)));
}
It would be
my2DArray[x][y+1]. C++ uses row-major order for multidimensional array indices. That means that large jumps in memory are changes in the left-most index, and single element jumps are changes in the right-most index.