I am using DelphiIXE.
I learned that GlobalMemoryStatus may return wrong results on 64 computers with more than
4G RAM, so GlobalMemoryStatusex should be used.
But, on the other hand, if I use GlobalMemoryStatusex on 32 computer, the results are wrong on as well (returned numbers are 0 or huge).
Of course I can prepare two programs: one for 64 and one for 32 computers,
and use the right memory status, but is there a way to use the same
call or recognize that computer is 64?
And do something like:
if comp64 then begin
GlobalMemoryStatusex
....
end
else begin
GlobalMemoryStatus
....
end;
This is the code I’m using now:
var
MS1: TMemoryStatusex;
begin
GlobalMemoryStatusex(MS1);
showmessage('KiloBytes of physical memory: '+FormatFloat('#,###" KB"', MS1.ullTotalPhys / 1024)+chr(10)+
'Percent of memory in use: '+Format('%d%%', [MS1.dwMemoryLoad])+chr(10)+
'KiloBytes of free physical memory: '+FormatFloat('#,###" KB"', MS1.ullAvailPhys /1024)+chr(10)+chr(10)+
'KiloBytes of paging file space: '+FormatFloat('#,###" KB"', MS1.ullTotalPageFile / 1024)+chr(10)+
'KiloBytes of free paging file space: '+FormatFloat('#,###" KB"', MS1.ullAvailPageFile / 1024)+chr(10)+chr(10)+
'KiloBytes of virtual address space: '+FormatFloat('#,###" KB"', MS1.ullTotalVirtual / 1024)+chr(10)+
'KiloBytes of free virtual address space: '+FormatFloat('#,###" KB"', MS1.ullAvailVirtual / 1024) );
Thanks in advance.
TOndrej, here is the code:
var MS1:TMemoryStatusex;
GlobalMemoryStatusex(MS1);
showmessage('KiloBytes of physical memory: '+FormatFloat('#,###" KB"', MS1.ullTotalPhys / 1024)+chr(10)+
'Percent of memory in use: '+Format('%d%%', [MS1.dwMemoryLoad])+chr(10)+
'KiloBytes of free physical memory: '+FormatFloat('#,###" KB"', MS1.ullAvailPhys /1024)+chr(10)+chr(10)+
'KiloBytes of paging file space: '+FormatFloat('#,###" KB"', MS1.ullTotalPageFile / 1024)+chr(10)+
'KiloBytes of free paging file space: '+FormatFloat('#,###" KB"', MS1.ullAvailPageFile / 1024)+chr(10)+chr(10)+
'KiloBytes of virtual address space: '+FormatFloat('#,###" KB"', MS1.ullTotalVirtual / 1024)+chr(10)+
'KiloBytes of free virtual address space: '+FormatFloat('#,###" KB"', MS1.ullAvailVirtual / 1024) );
It seems you are not initializing the structure and you’re not checking the return code. Here’s a compilable project which should work: