- - * - WhiteUnicorn - * - -




* #WhiteUnicorn/ StartPage/ Documentation/DelphiFAQ >


3231: Displaying System Resources in Win 95 and NT 4

KEYWORDS:  Displaying System Resources, TMemoryStatus, GlobalMemoryStatus AREA

                        Displaying System Resources

  This document describes the displaying of total system resources or
the amount of available system resources for Windows 95 or Windows NT
4.0. It includes the structure of the TMemoryStatus structure, the
function GlobalMemoryStatus that populates this structure as defined
in Windows.pas, and the Windows API header description. It also
includes a code example of populating a memo with this information
in Delphi.

  TMemoryStatus source can be found in Windows.PAS which is in the
Source\RTL\WIN directory if you have the Client\Server Suite of
Delphi.

Structure of TMemoryStatus:

  TMemoryStatus = record
    dwLength: DWORD;
    dwMemoryLoad: DWORD;
    dwTotalPhys: DWORD;
    dwAvailPhys: DWORD;
    dwTotalPageFile: DWORD;
    dwAvailPageFile: DWORD;
    dwTotalVirtual: DWORD;
    dwAvailVirtual: DWORD;

Function called to populate TMemoryStatus:

procedure GlobalMemoryStatus(var lpBuffer: TMemoryStatus); stdcall;

WINAPI help for said function:

  VOID GlobalMemoryStatus(
    // pointer to the memory status structure
    LPMEMORYSTATUS  lpBuffer
  );

Code for populating a TMemo with Information about system resources:

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls;

type
  TForm1 = class(TForm)
    Button1: TButton;
    Memo1: TMemo;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}

procedure TForm1.Button1Click(Sender: TObject);
var
  MemoryStatus: TMemoryStatus;

begin

  Memo1.Lines.Clear;

  MemoryStatus.dwLength := SizeOf(MemoryStatus);

  GlobalMemoryStatus(MemoryStatus);

  with MemoryStatus do
  begin
// Size of MemoryStatus record
    Memo1.Lines.Add(IntToStr(dwLength) +
      ' Size of ''MemoryStatus'' record');
// Per-Cent of Memory in use by your system
    Memo1.Lines.Add(IntToStr(dwMemoryLoad) +
      '% memory in use');
// The amount of Total Physical memory allocated to your system.
    Memo1.Lines.Add(IntToStr(dwTotalPhys) +
      ' Total Physical Memory in bytes');
// The amount available of physical memory in your system.
    Memo1.Lines.Add(IntToStr(dwAvailPhys) +
      ' Available Physical Memory in bytes');
// The amount of Total Bytes allocated to your page file.
    Memo1.Lines.Add(IntToStr(dwTotalPageFile) +
      ' Total Bytes of Paging File');
// The amount of available bytes in your page file.
    Memo1.Lines.Add(IntToStr(dwAvailPageFile) +
      ' Available bytes in paging file');
// The amount of Total bytes allocated to this program
// (generally 2 gigabytes of virtual space).
    Memo1.Lines.Add(IntToStr(dwTotalVirtual) +
      ' User Bytes of Address space');
// The amount of avalable bytes that is left to your program to use.
    Memo1.Lines.Add(IntToStr(dwAvailVirtual) +
      ' Available User bytes of address space');
  end; // with
end; // procedure

end.


Sample Output of what is contained in Memo1.Lines:

32: Size of 'MemoryStatus' record in bytes
76%: memory in use
33054720: Total Physical Memory in bytes
499712: Available Physical Memory in bytes
53608448: Total Bytes of Paging File
36372480: Available bytes in paging file
2143289344: User Bytes of Address space
2135556096: Available User bytes of address space

        TI



* #WhiteUnicorn/ StartPage/ Documentation/DelphiFAQ >



- - * - Anastasija aka WhiteUnicorn - * - - LJLiveJournal
PFPhotoFile