首页  编辑  

如何知道进程使用了多少内存

Tags: /超级猛料/OS.操作系统/Process.进程/   Date Created:

// Works only on Windows NT systems (WinNT, Win2000, WinXP)

uses psAPI ;

procedure TForm1 . Button1Click ( Sender : TObject );

var

 pmc : PPROCESS_MEMORY_COUNTERS ;

 cb : Integer ;

begin

 cb := SizeOf ( _PROCESS_MEMORY_COUNTERS );

 GetMem ( pmc , cb );

 pmc ^. cb := cb ;

  if GetProcessMemoryInfo ( GetCurrentProcess (), pmc , cb ) then

   Label1 . Caption := IntToStr ( pmc ^. WorkingSetSize ) + ' Bytes'

  else

   Label1 . Caption := 'Unable to retrieve memory usage structure' ;

 FreeMem ( pmc );

end ;