More memory efficient TDeque.IncreaseCapacity
Original Reporter info from Mantis: Alextp
-
Reporter name: CudaText man
Original Reporter info from Mantis: Alextp
- Reporter name: CudaText man
Description:
in fcl-stl gdeque:
procedure TDeque.IncreaseCapacity;inline;
...
if(FCapacity=0) then
FCapacity:=1
else
FCapacity:=FCapacity*2;
SetLength(FData, FCapacity);
...
in fcl-stl gvector:
procedure TVector.IncreaseCapacity();
begin
if FCapacity=0 then
FCapacity:=1
else
FCapacity:=FCapacity*2;
SetLength(FData, FCapacity);
end;
Suggestions:
- replace simple size*=2 logic with logic.
http://forum.lazarus.freepascal.org/index.php/topic,42852.msg299435.html#msg299435
it increases size by fixed size steps, when data size is huge. It must be not exponential grow (size*=2) for big sizes.
2) 1st step here changed to 4, coz >2 items in deque is often.
3) remove "inline" in both funcs, they will be more complex.
Mantis conversion info:
- Mantis ID: 34420
- Version: 3.0.4
- Fixed in version: 3.3.1
- Fixed in revision: 40214 (#cf4496aa)