Forum > General

Slow dispose

(1/1)

bigeno:
I've big problem with speed of my project, I made sample test with problem.

--- Code: ---type
  PStruct= ^TStruct;
  TStruct=record
    Size1: Integer;
    Size2: Integer;
  end;

var
  Form1: TForm1;
  st : PStruct;
  pp : array of PStruct;
  i: integer;

implementation

{$R *.lfm}

procedure TForm1.BitBtn1Click(Sender: TObject);
begin
 SetLength(pp,600000);
 for i:=0 to 600000 do begin
   New(st);
   st^.Size1:=-1;
   st^.Size2:=-1;
   pp[i]:=st;
 end;
end;

procedure TForm1.BitBtn2Click(Sender: TObject);
begin
 for i:=0 to 600000 do
   Dispose(PStruct(pp[i]));
end;
--- End code ---

The problem is with slow Dispose when I use cmem, with cmem dispose procedure is 10,15x slower then without cmem.
I need cmem in my project, can some one help with this ? ( I use Windows x64 and fpc,lazarus from trunk).

Leledumbo:

--- Code: ---{$mode objfpc}
uses
  cmem,sysutils,dateutils;
 
type
  PStruct= ^TStruct;
  TStruct=record
    Size1: Integer;
    Size2: Integer;
  end;

var
  st : PStruct;
  pp : array of PStruct;
  i: integer;
  bt,et: ttime;
begin
 SetLength(pp,600000);
 for i:=0 to 600000 do begin
   New(st);
   st^.Size1:=-1;
   st^.Size2:=-1;
   pp[i]:=st;
 end;
 bt := now;
 for i:=0 to 600000 do
   Dispose(PStruct(pp[i]));
 et := now;
 writeln(secondspan(bt,et):1:6);
end.

--- End code ---
Doesn't happen with above program on x86_64-linux with or without optimization. Even cmem actually makes the program faster: 0.010 s vs 0.012 s (without cmem) in average. If after you test above program the result is still the same, that would probably M$ faulty implementation of C memory manager.

bigeno:
Thanks, and sorry, there is no problem (just noticed what I was doing) ;)
My production version of project is ok, the problem is with IDE Debugger (whe I use Run on lazarus), only in that case Dispose is slow but this is no problem for me.  :)

User137:
You would gain a little speed perhaps by changing it to

--- Code: ---pp : array of TStruct;
--- End code ---
The pointer is making you use more memory for it.

edit: Well.. whatever you need for project, that seems just a hacky way to replicate behavior of TObject.

Navigation

[0] Message Index

Go to full version