You are not logged in.
Pages: 1
Thanks , ab.
I will follow your suggestions.
By the way
Check(ACities.Add(City)=i);
I cannot find out the declaration of procedure Check(...) , so just invoke ACities.add(City) directly.
ab, Thanks.
Type
TCity = packed Record
Name : String;
Country : String;
Latitude : double;
Longitude : double;
End;
TCityDynArray = Array Of TCity;
Var
City : TCity;
Cities : TCityDynArray;
ACities : TDynArray;
Procedure TForm1.Button1Click( Sender : TObject );
Var
i : integer;
CitiesCount:Integer;
Begin
ACities.Init(TypeInfo(TCityDynArray),Cities);
ACities.Clear;
for i:=0 to 100000 do begin
City.Name:='Name'+inttostr(i);
City.Country:='Country'+inttostr(i);
City.Latitude:=Random(10000) / 3;
City.Longitude:=Random(10000) / 3;
ACities.Add(City);
end;
End;
The codes will raise the "out of memory" exception certainly .
I am puzzled.
How can I post a executeable file(with source) ?
Thanks.
"see comments in source code about TDynArray.Init. If you want to add many data - use count pointer like in code below. Hope it help" from MPV
I changed the code following the suggestion, no issue .
......
ACities.Init(TypeInfo(TCityDynArray),Province.Cities);
ACities.Clear;
for i := 0 to 100000 do begin
......
Please , check the example code in delphi 7 . the codes will also raise "out of memory" exception
Thanks for the great job.
Following the example
var
City: TCity;
Cities: TCityDynArray;
ACities: TDynArray;
....
var i:integer;
begin
ACities.Init(TypeInfo(TCityDynArray),Cities);
for i:=0 to 100000 do begin <- Build a big array , and exception raised
City.Name := 'Iasi'+Inttostr(i);
City.Country := 'Romania';
City.Latitude := 47.16;
City.Longitude := 27.58;
ACities.Add(City);
end;
the codes above will raise "out of memory" exception , the memory occupied will reach the limition.
but if define ACities as TDynArrayhashed , the codes will execute normally, and the memory occupied 15-20M.
Please, how to use TDynArray to build a big array with at least one string type in the record ?
Pages: 1