Adress from array

BlitzMax Forums/BlitzMax Programming/Adress from array

local array:int[10]

and now i need the mem-address from value of array[0]

how to get it?

Just 'array' should give the pointer.

i think this works


Local array:Byte[10]
array[0]=123

mem=Int(Varptr(array[0]))
Print mem

Local zero:Byte Ptr
Print zero[mem]

or easier way:
Local array:Byte[10]
array[0]=123

Local mem:Byte Ptr=array

Print mem[0]


This will only work with simple datatypes, of course, as BlitzMax does not store object arrays in contiguous memory. It stores only pointers to those objects in the array and the objects elsewhere. Which makes sense being that types are always passed by reference, never by value, but I just thought it might be worth pointing out in case someone spots this thread and assumes object arrays work the same way.