|
A
dynamic array is like any other array in it's memory structure for it's element
data.
You
could however have two arrays with the second array being an array of
pointers/indexes to the first array elements.
If you
increase the length of a dynamic array, then it copies the whole
array.
Myles.
A quick question (I think). Does each item
of a dynamic array use sequential memory space or can each item be in a
completely different memory location? The reason I ask is I want to sort
an array of records (don't ask) and the quickest way would be to
swap pointer locations for each item, rather than move record values
themselves.
As I see it, it depends on whether SetLength moves the whole array to
another memory location as I believe it does with a dynamic
string.
I am trying to use a TStringList to do the
sorting and store the address of each array element in the Objects
property, but either it can't be done or I'm doing something wrong because the
records are ending up blank.
Files is an array of FileRec (a record
structure). PFileRec = ^FileRec;
var FileCnt:
Cardinal; FileList: TStringList; FileRecord:
PFileRec; begin FileList := TStringList.Create; for
FileCnt := 0 to High(Files) do
FileList.AddObject(ExtractFilename(Files[FileCnt].Filename),@Files[FileCnt]);
FileList.Sort; for FileCnt := 0 to High(Files) do
begin FileRecord :=
Pointer(FileList.Objects[FileCnt]); Files[FileCnt] :=
FileRecord^; end; FileList.Free;
end;
Cheers, Ross
Levis.
|
_______________________________________________
Delphi mailing list
[EMAIL PROTECTED]
http://ns3.123.co.nz/mailman/listinfo/delphi