This is a set of macros for handling dynamic arrays. It will be found in examples/constructs
When you have finished with a dynamic array, redimensioning it to 0 elements will release its memory space.
macro DynDim(t,v,n)
===================
t*v
@v=getmemory n*sizeof t
end macro
macro DynRedim(v,n)
===================
scope
sys p=@v
sys le
indexbase 0
if p
le=0xffffffff and *(p-4) 'length of original
end if
@v=getmemory n*sizeof v 'new mem block
if (le>n*sizeof v)
le=n*sizeof v 'clip data length to fit
end if
if le
copy @v,p,le 'copy data
end if
freememory p 'free original
end scope
end macro
macro DynSize(v)
================
(0xffffffff and *(@v-4))
end macro
macro DynCount(v)
================
((0xffffffff and *(@v-4))/ sizeof v)
end macro
'TEST: DYNAMIC 2 DIMENSIONAL ARRAY
'=================================
indexbase 0
sys nx=100,ny=50 'array size
DynDim double,d,nx*ny
'accessing array in 2 dimensions
macro da(x,y)
=============
d(x+y*nx)
end macro
da(50,10)=123.125
DynRedim d, nx*ny*2
print da(50,10) 'data is preserved
print DynSize d 'size of array in bytes
print DynCount d 'total number of elements
'Release Array Space
DynRedim d, 0
Charles