欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

delphi xe10 获取进程内存大

程序员文章站 2022-06-03 15:00:01
...

delphi xe10 获取本进程内存大小


uses
winapi.PsApi 

function GetCurrentProcessMemorySize(var nMemSize: Cardinal): Boolean;
var
  nWndHandle, nProcID, nTmpHandle: HWND;
  pPMC: PPROCESS_MEMORY_COUNTERS;
  pPMCSize: Cardinal;
begin
  nWndHandle := Application.Handle;
  if nWndHandle = 0 then
  begin
    Result := False;
    Exit;
  end;
  pPMCSize := SizeOf(PROCESS_MEMORY_COUNTERS);
  GetMem(pPMC, pPMCSize);
  pPMC^.cb := pPMCSize;
  GetWindowThreadProcessId(nWndHandle, @nProcID);
  nTmpHandle := OpenProcess(PROCESS_ALL_ACCESS, False, nProcID);
  if (GetProcessMemoryInfo(nTmpHandle, pPMC, pPMCSize)) then
    nMemSize := pPMC^.WorkingSetSize
  else
    nMemSize := 0;
  FreeMem(pPMC);
  CloseHandle(nTmpHandle);
  Result := True;
end;


function GetMemorySize: Int64;
var
l_size: Cardinal;
begin
  Result := 0;
 if GetCurrentProcessMemorySize(l_size) then
   Result := l_size;
end;