Thanks to this post, which gives hints on how to get virtual size using C / C ++, I was able to write the following Delphi function:
Type TMemoryStatusEx = packed record dwLength: DWORD; dwMemoryLoad: DWORD; ullTotalPhys: Int64; ullAvailPhys: Int64; ullTotalPageFile: Int64; ullAvailPageFile: Int64; ullTotalVirtual: Int64; ullAvailVirtual: Int64; ullAvailExtendedVirtual: Int64; end; TGlobalMemoryStatusEx = function(var MSE: TMemoryStatusEx): LongBool; stdcall; function VirtualSizeUsage: Int64; var MSE: TMemoryStatusEx; fnGlobalMemoryStatusEx: TGlobalMemoryStatusEx; begin Result := 0; @fnGlobalMemoryStatusEx := GetProcAddress(GetModuleHandle(kernel32), 'GlobalMemoryStatusEx'); if Assigned(@fnGlobalMemoryStatusEx) then begin MSE.dwLength := SizeOf(MSE); if fnGlobalMemoryStatusEx(MSE) then Result := MSE.ullTotalVirtual-MSE.ullAvailVirtual; end; end;
It seems to work fine for me (Delphi 6, Win XP). It may be easier to find a GlobalMemoryStatus solution instead of a GlobalMemoryStatusEx but it will not work correctly on systems with more than 2 GB of memory.
source share