Can you dynamically resize an array?

rolypolyman_at_gmail.com
Date: 01/20/05


Date: 20 Jan 2005 14:48:46 -0800

To anyone --

What do you do when you're dealing with arrays whose size you
can't predict? Take the following illustrative example:

var
myarray : array[1..400] of integer;
mystring : string;
myinteger, errx : integer;
begin
assignfile(infile,'c:\myfile');
reset(infile);
while not eof(infile) do
begin
readln(infile,mystring);
val(copy(mystring,10,4),myinteger,errx);
inc(x);
myarray[x] := myinteger;
end;
..... do something with myarray[]
end;

How do you handle this when you can't predict how many lines of
text will be in the file? What if the user has a file containing
8000 lines of data?

It would be nice to allocate only a small amount of memory and have
the array automatically resize itself as it goes. How is this
usually done? I know I can work with pointers, too, but I'm not
clear on how to automatically resize those either.

Thanks,

RPM



Relevant Pages

  • Re: Operations on derived type arrays
    ... "I get the impression that Richard is talking a bit past you." ... arrays of structures versus structure of arrays. ... access all the elements of myArray and USED ... layout affects performance. ...
    (comp.lang.fortran)
  • Re: Dim MyArray vs. Dim MyArray()
    ... from the errors thrown above it seems abundantly clear that the two ... > MyArray2are true Variant() arrays and not Variant variables ... > containing arrays (if they were the latter, then, as demonstrated above, ... Dim myArray() ...
    (microsoft.public.excel.programming)
  • Re: debugging code (was Re: semicolon adding nops?)
    ... should have about how to actually look at the data from arrays? ... see is isa, class, superclass, and all that stuff. ... can say, while stopped at a breakpoint, in the debugging console window: ... po [myArray objectAtIndex:3] ...
    (comp.sys.mac.programmer.help)
  • Re: Altering Array Sizes within Functions
    ... > Im having trouble with arrays ... > The function modifies the size and elements of myArray. ...
    (comp.lang.cpp)