Hi Brad,
I think your problem lies in the definition of the TSortArr-record type
where you're using a WideString type:
[CODE]
type
TSortArr = record
Val: string;
Rec: cardinal;
end;
[/CODE]
I think it's better if you'd use a ShortString (with its size set to the
same size as set in the field), like:
[CODE]
Type
TSortArr = Packed Record
Val : String[100]; // <== Set to your needs...
Rec : Cardinal;
End;
[/CODE]
See if that helps ;)
Greetz,
Peter.
From: Brad Hall <[email protected]
<mailto:brad.hall%40semagroup.com.au> >
Subject: [delphi-en] Record memory issue
To: [email protected] <mailto:delphi-en%40yahoogroups.com>
Date: Monday, November 16, 2009, 7:22 PM
Hi everyone,
I have a query about records + their memory usage.
I've created a record to hold a couple of values, which I then do a
quicksort (a separate procedure) on.
The drama is, the code never gets the chance to do the quicksort due to
the record consuming RAM at an unbelievable rate - hundreds of MB of RAM
until I get the "Out of Memory" error.
The values I'm loading into the record are a subset from a file only
1.01Mb in size (I've loaded the file into a TClientDataSet) .
I tried loading the same values that I was loading into the record into
a TStringList, + the resulting amount of memory used was less than 1Mb
(as it should be).
I also tried using a packed record but that didn't alleviate the problem
(I don't really like packed records either...).
The string values I'm loading into the record are only 1 character
each...
I don't see how the record is consuming so much memory! The only thing I
can think of at the moment is the way I'm allocating memory to the
record (SetLength).
Does anyone have any other ideas??
Code is:
procedure Process;
type
TSortArr = record
Val: string;
Rec: cardinal;
end; //type
var
SortArr: array of TSortArr;
SortStr: string;
RowCnt: cardinal;
begin
RowCnt := 0;
while (NOT cdsInputFile. EOF) do
begin
SortStr := <data from cds>;
SetLength(SortArr, RowCnt + 1);
SortArr[RowCnt] .Val := SortStr;
SortArr[RowCnt] .FPos := cdsInputFile. RecNo;
Inc(RowCnt);
ReadRecord; //get next rec in file
end; //while not eof
end;
Thanks :-)