Παρασκευή 11 Μαΐου 2012

Get Process Memory Info

If you want to know how many bytes of memory is using your process, here is simple example.
We will need standard psAPI unit. Using API function GetProcessMemoryInfo, we can get amount of used bytes of memory.

unit Unit1;
 
interface
 
uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, psAPI;
 
type
  TForm1 = class(TForm)
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;
 
var
  Form1: TForm1;
 
implementation
 
{$R *.dfm}
 
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 
        ShowMessage(IntToStr(pmc^.WorkingSetSize) + ' Bytes')
  else 
        ShowMessage('Unable to get process info');
  FreeMem(pmc);
end;
 
end.

Δεν υπάρχουν σχόλια:

Δημοσίευση σχολίου