频道分类

Delphi GetProcessMemoryInfo获取进程占用内存大小

作者:admin 来源: 日期:2019/10/5 13:35:55 人气: 标签:

 

uses
psAPI;


procedure ShowMemUsage(PID:Cardinal);
var
    memCounters:_PROCESS_MEMORY_COUNTERS;
    h:cardinal;
begin
    ZeroMemory(@memCounters,sizeof(memCounters));
    h:=OpenProcess(PROCESS_QUERY_INFORMATION or PROCESS_VM_READ, false, PID);
    if h<>0 then begin
        memCounters.cb := sizeof(memCounters);
        if not GetProcessMemoryInfo(h, @memCounters, sizeof(memCounters)) then
            showmessage('Coulnd''t get memory info!')
        else
            showmessage('Current : '+inttostr(memCounters.WorkingSetSize shr 10)+' K'#13#10+'Peak : '+inttostr(memCounters.PeakWorkingSetSize shr 10 )+' K'#13#10+'Pagefile : '+inttostr(memCounters.PageFaultCount shr 10)+' K');
        closehandle(h);
    end;
end;


procedure TForm1.FormCreate(Sender: TObject);
begin
ShowMemUsage(8512);

end;