Thanks Oscar,
I've developed this example a bit more, and given O2 all the responsibility for creating and managing the array-space. The array-space is only freed when finish() is executed.
You have to be careful about when variables are created on the thinBasic side.
uses "oxygen"
'SHARED VARIABLES
'================
dim as string src
dim as long pCreateArray3d
dim as long pFinish
'
'OXYGENBASIC SECTION
'===================
src="
#minormajor 'thinBasic and Powerbasic mode
indexbase 1
redim single v(0,0,0)
sub CreateArray3d(sys *pv, long x,y,z) link #pCreateArray3d
redim single v(x,y,z)
pv=@v 'link to host variable v
dim as long c,x,y,z
for z=1 to 4
for y=1 to 4
for x=1 to 4
c++
v(x,y,z)=c 'fill 1 to 64
next
next
next
end sub
sub finish() link #pFinish
freememory @v
terminate
end sub
"
'COMPILE
'=======
o2_basic src
if o2_errno then
msgbox 0,o2_error
stop
else
o2_exec
'msgbox 0,"ok"
end if
'MAIN THINBASIC SECTION
'======================
declare sub CreateArray3d(byref pv as long, byval x as long, byval y as long, byval z as long ) at pCreateArray3d
declare sub Finish() at pFinish
dim as long pv
dim as long x,y,z
x=4
y=4
z=4
CreateArray3d(pv,x,y,z)
'msgbox 0,pv
dim as single v(x,y,z) at pv
'array Order: 17 18 19 20
msgbox 0,"Order: "+v(1,1,2)+", "+v(2,1,2)+", "+v(3,1,2)+", "+v(4,1,2)
finish()