Hi Brian,
This is an example string array class which uses a dynamic buffer with its own redim. It also uses bstrings, so garbage collection is totally managed by the redim and destructor methods.
$filename "t.exe"
'uses rtl64
class Buffer
============
sys bu 'buffer
int bl 'buffer length bytes
'
function redim(int i)
=====================
sys nbu
int nbl
nbl=i*sizeof(sys)
nbu=getmemory nbl
int e=bl
if bl
if bl>nbl then e=nbl
copy nbu,bu,e
freememory bu
endif
bu=nbu
bl=nbl
end function
'
function constructor(int i)
===========================
this.redim(i)
end function
'
function destructor()
===================
freememory bu
bu=0
bl=0
end function
'
end class
class ArrayString
=================
'
indexbase 0
'
has buffer b
int ns 'number of strings
'
function redim(int i)
=====================
b.constructor(i+1)
end function
'
function constructor(int i)
===========================
b.constructor(i+1)
int j
bstring s at (b.bu)
for j=0 to i
s[i]=""
next
ns=i+1
end function
'
function destructor()
=====================
int i
bstring s at (b.bu)
for i=0 to ns-1
frees s[i]
next
b.destructor()
end function
'
function vs(int i) as string
============================
bstring s at (b.bu)
if (i>=0)and(i<ns)
return s(i)
else
'out of bounds error
endif
end function
'
function vs(int i,string t)
===========================
bstring s at (b.bu)
if (i>=0)and(i<ns)
s(i)=t
else
'out of bounds error
endif
end function
'
function lbound() as int
========================
return 0
end function
'
function ubound() as int
========================
return ns-1
end function
'
end class
'TESTS
======
new ArrayString ss(99)
ss.vs(50)="okay"
ss.redim(200)
ss.redim(70)
print ss.vs(50) ", " ss.ubound()
del ss
copy nbu,bu,e
Fixed!