Board index » delphi » Dynamic arrays of records

Dynamic arrays of records

Help,

The section on dynamic arrays only shows using data types.  Can you use
a dynamic array of a fixed length record without using something to
allocate and deallocate memory?  Does it make a difference if one of the
items is a variable length string?  Would using string[n] help?

Something = record
d1 : integer;
d2 : string;   or string[48] if this helps.
d3 : double;
end;
...
...
private
  things : array of something;
...
...
setlength(things,200);

Or would it be better to use the following and not have to worry about
memory allocation?

thingd1 : array of integer;
thingd2 : array of string;
thingd3 : array of double;
...
...
setlength(thingd1,200);
setlength(thingd2,200);
setlength(thingd3,200);

p.s. Does thingd2 take care of all of the memory related actions
required for the individual string variables?

 

Re:Dynamic arrays of records


Im Artikel <3A0695D5.4D1A4...@azdogs.com>, Jim Andrews <j...@azdogs.com>
schreibt:

Quote
>The section on dynamic arrays only shows using data types.  Can you use
>a dynamic array of a fixed length record without using something to
>allocate and deallocate memory?

Yes. Records also are data types ;-)

Quote
>Does it make a difference if one of the items is a variable length string?

No.

Quote
>Would using string[n] help?

Some string handling may become faster with fixed size strings, but some
(most?) can take much more time.

Since it's a simple change from "string" to "string[n]", you can write the
program first, and then check which version is faster.

DoDi

Other Threads