Slow dispose lazarus / 62-General ---------------------------------------------------------------------- bigeno · 2014-06-29 11:33 I've big problem with speed of my project, I made sample test with problem. Code: [Select]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; 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 · 2014-06-29 11:47 Code: [Select]{$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. 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 · 2014-06-29 12:05 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 · 2014-06-29 13:12 You would gain a little speed perhaps by changing it to Code: [Select]pp : array of TStruct;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.