chami.com/tips/
Last  Home  Next
 Internet
 Programming
 Windows


Click for details
Keywords
Delphi 2.x
Delphi 3.x
Delphi
Functions
Win32

Downloads
memstat.pas
memtotal.pas

GlobalMemoryStatus() to the rescue

    See Also
  Give your 16bit program its own space (Windows tip)

"GetFreeSystemResources()" Win16 API function is no longer supported in Win32 API, but you can use "GlobalMemoryStatus()" to get even more memory related information:

var
  ms : TMemoryStatus;
begin
  ms.dwLength := SizeOf( ms );
  GlobalMemoryStatus( ms );
  with ms do
  begin
    //
    // now you can use any of 
    // the following parameters
    //

    // percent of memory in use
    {dwMemoryLoad}

    // bytes of physical memory
    {dwTotalPhys}

    // free physical memory bytes
    {dwAvailPhys}

    // bytes of paging file
    {dwTotalPageFile}

    // free bytes of paging file
    {dwAvailPageFile}

    // user bytes of address space
    {dwTotalVirtual}

    // free user bytes
    {dwAvailVirtual}
  end;
end;
Listing #1 : Delphi code. Right click memstat.pas to download.

For example:

function GetMemoryTotalPhys : DWord;
var
  ms : TMemoryStatus;
begin
  ms.dwLength := SizeOf( ms );
  GlobalMemoryStatus( ms );
  Result := ms.dwTotalPhys;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  MessageDlg(
    'total physical memory: ' +
    IntToStr( GetMemoryTotalPhys )
    , mtInformation, [mbOk], 0 );
end;
Listing #2 : Delphi code. Right click memtotal.pas to download.

 
Related Links Email Print 
Created on 24-Dec-1996. Source code colorized using CodeColorizer.
Copyright (C) 1996-99 Chami.com All Rights Reserved. Reproduction in whole or in part
or in any form or medium without express written permission of Chami.com is prohibited.
Information on this page is provided as-is without warranty of any kind. Use at your own risk.
Free Downloads | Products & Services | Privacy Statement | Terms & Conditions | Advertising Info