new list as ScalableData
for i = 1 to 100
print "adding item: "; i
call list::add i
next i
class ScalableData
dim storage(10)
dim expandBy
dim length
dim amount
sub ScalableData
expandBy = 10
length = 0
amount = 10
end sub
sub add item
length = length + 1
if length > amount then
amount = amount + expandBy
call preserve storage(), amount
end if
storage(length) = item
end sub
end class
function nsize(array())
' Returns the upper index limit of the numeric array array().
s = 2^24
do
on error goto [Error]
[Error]
s = int(s / 2)
temp = array(nsize + s)
nsize = nsize + s
loop until s = 0
end function
sub preserve byref array(), newSize
' Redimensions the given one-dimensional numeric array to the
' specified newSize.
u = nsize(array()) ' Get the upper limit
redim ArrayLib(u)
for i = 0 To u
ArrayLib(i) = array(i) ' Get old contents
next i
redim array(newSize) ' Resize given array.
for i = 0 To u
array(i) = ArrayLib(i) ' Replace old contents
next i
end sub
new list as List
for i = 1 to 100
print "adding item: "; i
call list::add i
next i
class List
dim temp(1)
dim storage(10)
dim expandBy
dim size
dim amount
sub List
expandBy = 10
size = 0
amount = 10
end sub
sub add item
size = size + 1
if size > amount then
amount = amount + expandBy
call this::expand amount
end if
storage(size) = item
end sub
private sub expand newSize
redim temp(size)
for i = 0 to size
temp(i) = storage(i)
next i
redim storage(newSize)
for i = 0 to size
storage(i) = temp(i)
next i
redim temp(1)
end sub
end class