DelphiDabbler Code Snippets Database

Snippet Selection

The following snippets from the Code Snippets Database have been requested.

GetAvailablePhysMemory

Returns the currently available physical memory in bytes. Returns 0 on error. Use GetLastError to get the error code.

function GetAvailablePhysMemory: Int64;
var
  MemoryEx: Windows.TMemoryStatusEx;
begin
  begin
    MemoryEx.dwLength := SizeOf(Windows.TMemoryStatusEx);
    Windows.GlobalMemoryStatusEx(MemoryEx);
    Result := MemoryEx.ullAvailPhys;
  end;
end;

GetPercentMemoryUsed

Returns the approximate percentage of total physical memory that is currently in use. Returns 0 on error. Call GetLastError to get the error code.

function GetPercentMemoryUsed: Byte;
var
  MemoryEx: Windows.TMemoryStatusEx;
begin
  begin
    MemoryEx.dwLength := SizeOf(Windows.TMemoryStatusEx);
    Windows.GlobalMemoryStatusEx(MemoryEx);
    Result := Byte(MemoryEx.dwMemoryLoad);
  end;
end;

View the whole database.

Go to the DelphiDabbler website.