Smart-Basic Array Order

Post Reply
User avatar
MarkP
Posts: 71
Joined: Tue Apr 07, 2015 9:32 pm

Smart-Basic Array Order

Post by MarkP »

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).

User avatar
Mr. Kibernetik
Site Admin
Posts: 4782
Joined: Mon Nov 19, 2012 10:16 pm
My devices: iPhone, iPad, MacBook
Location: Russia
Flag: Russia

Re: Smart-Basic Array Order

Post by Mr. Kibernetik »

Internally smart BASIC uses column-major ordering.
But you cannot detect this by your BASIC program because BASIC language does not use pointers. Also don't forget that smart BASIC uses complex numbers, not real numbers.

User avatar
MarkP
Posts: 71
Joined: Tue Apr 07, 2015 9:32 pm

Re: Smart-Basic Array Order

Post by MarkP »

Yes, I am aware that I cannot detect the array ordering by myself. (I tried using debug) However, it is still good to know so that I can properly order the array indexes so that sequential reading of the array is via the major index to allow the processor to cache data accesses, if possible.

Post Reply