1,594
社区成员




var
a:TRTLCS;
i:integer;
p:Pointer;
Len:Integer;
t1,t2,t3,t4:LongWord;
P1,P2:Integer;
begin
Len:=999999;
//分配Len次内存和进行Len次临界区那个速度快
t1:=GetTickCount;
for i:=0 to Len do
begin
p:=GetMemory(1024*4);
FreeMemory(p);
end;
t2:=GetTickCount;
a:=TRTLCS.Create;
t3:=GetTickCount;
for i:=0 to Len do
begin
a.Lock;
P1:=i;
P2:=P1;
a.Unlock;
end;
t4:=GetTickCount;
t2:=t2-t1;
t4:=t4-t3;
Showmessage(Format('%d %d',[t2,t4]));
end;
测试了一下,4633 62
还是进临界区速度快,还快好多。看来得先分配好内存,然后直接使用效率最高。