Smart-Basic Array Order
Posted: Sun Dec 06, 2020 1:19 am
I have no idea whether the Apple CPU chips in the iphone and ipad devices benefit from cache memory, but just in case they do, I wanted to set the order of array indexes properly to take advantage of memory caching, especially with using large 3-dimensional arrays.
To do this, I needed to determine whether arrays in smart BASIC are ordered in "column-major-order" (first index causes memory-contiguous elements) or "row-major-order" (last index causes memory-contiguous elements).
Since SB shields the programmer from memory layout information, I figured I'd use "debug" to determine the layout of 3-dimensional arrays.
To my surprise, based on the order that debug indicates, SB is neither column-major nor row-major.
Try the following code:
option base 1
n=0
dim a(4,4,4)
for x=1 to 4
for y=1 to 4
for z=1 to 4
n+=1
a(y,z,x)=n 'NOTE THIS ORDER
next z
next y
next x
debug pause
Can anyone assist with this?
I expected either (x,y,z) or (z,y,x), but NOT (y,z,x).
To do this, I needed to determine whether arrays in smart BASIC are ordered in "column-major-order" (first index causes memory-contiguous elements) or "row-major-order" (last index causes memory-contiguous elements).
Since SB shields the programmer from memory layout information, I figured I'd use "debug" to determine the layout of 3-dimensional arrays.
To my surprise, based on the order that debug indicates, SB is neither column-major nor row-major.
Try the following code:
option base 1
n=0
dim a(4,4,4)
for x=1 to 4
for y=1 to 4
for z=1 to 4
n+=1
a(y,z,x)=n 'NOTE THIS ORDER
next z
next y
next x
debug pause
Can anyone assist with this?
I expected either (x,y,z) or (z,y,x), but NOT (y,z,x).