No problem
MakeMemblockArray(1,10,10)
SetMemblockArray(1, 0, 5, 9)
for y=0 to 10
for x=0 to 10
print GetMemblockArray(1, X, Y); " ";
next x
print
next y
wait key
end
function MakeMemblockArray(MB as integer, x as integer, y as integer)
inc x
inc y
make memblock MB, (x*y*4)+8
write memblock dword MB, 0, x
write memblock dword MB, 4, y
endfunction
function SetMemblockArray(MB as integer, x as integer, y as integer, v as integer)
write memblock dword MB, __MakeMemblockArrayAddr(MB, X, Y), v
endfunction
function GetMemblockArray(MB as integer, x as integer, y as integer)
local v as integer
v = memblock dword( MB, __MakeMemblockArrayAddr(MB, X, Y) )
endfunction v
function __MakeMemblockArrayAddr(MB as integer, X as integer, Y as integer)
local Addr as integer
Addr = (X*4) + ( memblock dword(MB, 4) * Y * 4) + 8
endfunction Addr
Notes:
No bounds checking has been done - both x and y dimensions have been stored in the memblock, so you could add this
Only 2D - expanding to 3D shouldn't be a problem for you though as it's pretty much more of the same.
I have emulated DBPro array sizing here by allowing you to access from 0 to the size you specify.
Oh, and memblocks will be slower than arrays, but it's probably a bit early to move you onto raw memory access which would only be marginally slower. Stick with using these functions, and it'll be easier to move onto that later if you need the speed.