On Oct 22, 2004, at 1:53 PM, Gohara, David wrote:
Hi All,
Two memory related questions. One is 2D and the other is 3D.
The 2D question. In a 173x173 data array I get the following
memory addresses for y,x combinations:
86,86 6bc89d0
73,85 6be3a4c
74,81 6be3cF0
68,82 6c00060
The address jump from 86,86 to 73,85 doesn't make sense to me
(although it's consistent for the 73,85 to 74,81) according to my
calculations (which in all honesty could be very wrong). To get the
addresses I used printf("ptr %x\n",ptr); Any ideas what I've done
wrong? The answer after all the computing is correct, but these
addresses seem wrong.
Regarding a 3D array this is similar to my last question regarding
transposing a 2D array. Except this time I was wondering if it's
possible to do this across the third dimension (that is all values in
the third direction would become a stride of 1). I thought about
this a while now, but I've now gotten myself completely confused and
am asking for help. Previously I took the easy way and used mtrans()
as was kindly suggested.
It seems likely that the elements in your array are 4 byte quantities,
the row (or column in FORTRAN) is 173*4 bytes wide (692 bytes). So to
get from 73,85 to 74,81, you add 74-73=1 row (or column) and add
81-85= -4 elements:
delta = 1 row * 692 bytes/row + -4 * 4 bytes/element = 676 bytes
(0x2a4)
6be3cF0 - 6be3a4c = 0x2a4