取当前进程内存使用量

时间:2020-12-10 23:22:58

 

使用单元:uses Psapi;

 

procedure TForm1.Button10Click(Sender: TObject);
var
b: Boolean;
pmc: TProcessMemoryCounters;
h: THandle;
I, J: Integer;
begin
h := GetCurrentProcess;
b := GetProcessMemoryInfo(h, @pmc, SizeOf(TProcessMemoryCounters));
if b then
begin
self.Memo1.Lines.Add(FormatDateTime('hh:mm:ss.zzz ', Now) + IntToStr(pmc.WorkingSetSize));
end;


// for I := 1 to 100 do
// begin
// SetLength(DataInfo, I);
//// for J := 0 to I - 1 do
//// DataInfo[J].ID := J;
// end;
//
// for I := 100 downto 1 do
// begin
// SetLength(DataInfo, I);
//// for J := 0 to I - 1 do
//// DataInfo[J].ID := J;
// end;
b := GetProcessMemoryInfo(h, @pmc, SizeOf(TProcessMemoryCounters));
if b then
begin
self.Memo1.Lines.Add(FormatDateTime('hh:mm:ss.zzz ', Now) + IntToStr(pmc.WorkingSetSize));
end;
end;