Why is DeleteCriticalSection so much slower than InitializeCriticalSection?
I have more than 20000 CriticalSections need to delete when application close or serivce stop. But I found the DeleteCriticaSection function i开发者_如何学Cs very slow. I do a test:
var
CC: array[1..20000] of TRTLCriticalSection;
procedure TForm1.Button1Click(Sender: TObject);
var
T: Cardinal;
I: Integer;
begin
Memo1.Lines.Add('InitializeCriticalSection:');
T := GetTickCount;
for I := 1 to 20000 do
InitializeCriticalSection(CC[i]);
Memo1.Lines.Add(IntToStr(GetTickCount - T));
EnterCriticalSection(CC[3009]);
Memo1.Lines.Add('--------------');
LeaveCriticalSection(CC[3009]);
Memo1.Lines.Add('DeleteCriticalSection:');
T := GetTickCount;
for I := 1 to 20000 do
DeleteCriticalSection(CC[i]);
Memo1.Lines.Add(IntToStr(GetTickCount - T));
end;
The Result:
InitializeCriticalSection:
62
--------------
DeleteCriticalSection:
2262
Have any good suggestions?
精彩评论