вот и получается - сколькото довыделений и сколькото полноценных выделений с перемещением
А как насчет StrNew(Pchar) vs AnsiString(refcounting) ?
Модератор: Модераторы
вот и получается - сколькото довыделений и сколькото полноценных выделений с перемещением
fpc-stl чем не велокиллер?
zub писал(а):fpc-stl чем не велокиллер? тем что на генериках?
это просто обертка над динмассивом с допфичами
zamtmn@zamtmn-desktop:/mnt/wind/array$ time ./v4
Heap dump by heaptrc unit
1800025 memory blocks allocated : 124043278/129349960
1800025 memory blocks freed : 124043278/129349960
0 unfreed memory blocks : 0
True heap size : 57376768
True free heap : 57376768
real 0m1.256s
user 0m1.224s
sys 0m0.028s
zamtmn@zamtmn-desktop:/mnt/wind/array$ time ./v4
real 0m0.235s
user 0m0.208s
sys 0m0.024s
program test;
{$mode objfpc}{$h+}
uses
decal in 'decal\decal.pas',
mwfixedrecsort in 'decal\mwfixedrecsort.pas',
sysutils,
classes
;
const
TEST_CNT = 300000;
type
chmoclass = class
public
int_val: integer;
str_val: widestring;
constructor create(const aint: integer; const astr: widestring);
end;
constructor chmoclass.create(const aint: integer; const astr: widestring);
begin
int_val:= aint;
str_val:= astr;
end;
procedure PrintData(ptr: pointer; const obj: dobject);
begin
case obj.vtype of
vtInteger:
writeln('atomic int = ',asInteger(obj));
vtString,vtWidestring:
writeln('atomic widestring = ',asWideString(obj));
vtExtended:
writeln('atomic real = ',asEXtended(obj));
vtObject: begin
with chmoclass(asClass(obj)) do begin
writeln('chmo data = {',int_val,',',str_val,'}');
free;
end;
end;
end;
end;
var
lst1: dlist;
i: integer;
begin
lst1:= dlist.create;
for i:= 0 to TEST_CNT do begin
lst1.add([i]);
lst1.add([extended(i)]);
lst1.add([widestring(inttostr(i) + ' as text')]);
lst1.add([chmoclass.create(i,inttostr(i) +' as text in CHMOREC')]);
end;
foreach(lst1,MakeApply({$ifdef fpc}@{$endif}PrintData));
lst1.free;
end.
zamtmn@zamtmn-desktop:/mnt/wind/array/v5$ time ./v5
real 0m0.360s
user 0m0.316s
sys 0m0.040s
zamtmn@zamtmn-desktop:/mnt/wind/array$ time ./v0
real 0m1.485s
user 0m0.776s
sys 0m0.704s
program v4;
{$mode objfpc}{$h+}
uses
sysutils,strings,gvector;
const
TEST_CNT = 300000;
type
chmorec = packed record
int_val: integer;
str_val: pchar;
end;
pchmorec = ^chmorec;
ANYTYPE = (INT_T,TEXT_T,REAL_T,CHMO_T);
anydatarecty = packed record
case data_type:ANYTYPE of
INT_T: (ival: integer);
TEXT_T: (tval: pchar);
REAL_T: (rval: double);
CHMO_T: (chmoval: chmorec);
end;
//anydatarecarty = array of anydatarecty;
anydatarecarty=specialize TVector<anydatarecty>;
procedure addelem(var arr: anydatarecarty; atype:ANYTYPE; adataptr: pointer);
var
adata:anydatarecty;
begin
//setlength(arr,length(arr)+1);
adata.data_type:= atype;
// case integer(atype) of
// integer(INT_T): arr[high(arr)].ival:= integer(adataptr^);
// integer(TEXT_T): arr[high(arr)].tval:= strnew(pchar(adataptr));
// integer(REAL_T): arr[high(arr)].rval:= double(adataptr^);
// integer(CHMO_T): begin
// with arr[high(arr)].chmoval do begin
// int_val:= (chmorec(adataptr^)).int_val;
// str_val:= strnew((chmorec(adataptr^)).str_val);
// end;
// end;
// end;
case atype of
INT_T: adata.ival:= integer(adataptr^);
TEXT_T: adata.tval:= strnew(pchar(adataptr));
REAL_T: adata.rval:= double(adataptr^);
CHMO_T: begin
with adata.chmoval do begin
int_val:= (chmorec(adataptr^)).int_val;
str_val:= strnew((chmorec(adataptr^)).str_val);
end;
end;
end;
arr.PushBack(adata);
end;
var
arr1: anydatarecarty;
i1: integer;
pch1: pchar;
r1: double;
chmo1: chmorec;
i: integer;
begin
arr1:=anydatarecarty.Create;
for i:= 0 to TEST_CNT do begin
i1:= i;
addelem(arr1,INT_T,@i1);
r1:= double(i);
addelem(arr1,REAL_T,@r1);
pch1:= pchar(inttostr(i) + ' as text');
addelem(arr1,TEXT_T,pch1);
chmo1.int_val:= i;
chmo1.str_val:= pchar(inttostr(i) +' as text in CHMOREC');
addelem(arr1,CHMO_T,@chmo1);
end;
for i:=arr1.Size downto 0 do begin
case integer(arr1[i].data_type) of
// integer(INT_T): writeln('int val = ', arr1[i].ival);
integer(TEXT_T): begin
// writeln('text val = ', arr1[i].tval);
dispose(arr1[i].tval);
end;
// integer(REAL_T): writeln('real val = ', arr1[i].rval);
integer(CHMO_T): begin
// writeln('chmo rec = {', arr1[i].chmoval.int_val,',',arr1[i].chmoval.str_val, '}');
dispose(arr1[i].chmoval.str_val);
end;
end;
end;
arr1.Destroy;
end.
Сейчас этот форум просматривают: нет зарегистрированных пользователей и гости: 6