During Friday August 18 1995, paul sjoerdsma transmogriphed to All about
Creating Arrays of Variable Size at Runtime:
ps> Although I'm using Delphi this is probably an Object Pascal question.
ps> Is it possible to create an array of variable size at runtime?
IF you do like you currently do, allocating an array of fixed (known) max
items, then defining on which is closest to 64K will do the trick if you don't
use NEW(); but GETMEM();
ps> Is something like this possible in Object Pascal, or do I still have to
ps> use:
ps> TYPE
ps> LargeArrayPtr = ^LargeArray;
ps> LargeArray = ARRAY[1..1500] OF REAL;
ps> VAR
ps> someArray = LargeArrayPtr;
GETMEM(SomeArray,4*ItemsYouNeed);
{4= size of a pointer, you can substitute "4" with "SIZEOF(POINTER)" as it is
more 'accurate' I think.}
Now to use it DON'T adress items higher than allocated.
deallocating requires FREEMEM is I think it also requires the size of the item
freed so look these commands up in the online help to check out the exact way
to call them.
ps> and then create this array dynamically??? Which means I will always
ps> have to anticipate the largest possible size.
You still have to anticipate the max possible (or allowed) items. But if you
don't allow Pascal's runtime check for your adressing you can make an array of
1 item and do the checking yourself - the point being not to allocate an array
larger than 64K and using it not to adress items extending the amount
allocated.
I hope I do not have to tell you this is completely untested and as it so
happens out of my head. But i think it is worth a try - I vagely remember
toying with this approach 4 years ago.
Maybe you'll find som freedom in this approach if it works, maybe you'll find
it tedious to do the checking yourself.
Regards
-Mikkel Breiler (Vinyl/iNTUiTiON & Sofi/DiskDoublers)
InterNet: mbrei...@renoz.ping.dk. Fido: 2:236/501.28, 2:236/86.28.