#2 Re: Source Code repository » SynCommons: TDynArray and Record compare/load/save using fast RTTI » 2012-10-04 10:36:51

cg

By the way

Check(ACities.Add(City)=i);

I cannot find out the declaration of procedure Check(...) , so just invoke ACities.add(City) directly.

#3 Re: Source Code repository » SynCommons: TDynArray and Record compare/load/save using fast RTTI » 2012-10-04 10:30:18

cg

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) ?

#4 Re: Source Code repository » SynCommons: TDynArray and Record compare/load/save using fast RTTI » 2012-10-03 23:01:54

cg

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

#5 Re: Source Code repository » SynCommons: TDynArray and Record compare/load/save using fast RTTI » 2012-10-03 14:03:15

cg

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 ?

Board footer

Powered by FluxBB