Get full and available memory when installing> 4 GB

Is there a way to get full and available memory if more than 4 GB of memory is installed on Windows 7 with Delphi 2010?

This code does not return more than 3.99 GB:

var Memory: TMemoryStatus; Memory.dwLength := SizeOf( Memory ); GlobalMemoryStatus( Memory ); dwTotalPhys1.Caption := 'Total memory: ' + IntToStr( Memory.dwTotalPhys ) + ' Bytes ' + '(' + FormatByteSize ( Memory.dwTotalPhys ) + ')'; dwAvailPhys1.Caption := 'Available memory: ' + IntToStr( Memory.dwAvailPhys ) + ' Bytes ' + FormatByteSize ( Memory.dwAvailPhys ) + ')'; 
+6
source share
2 answers

You need to use GlobalMemoryStatusEx . GlobalMemoryStatus limited to 4gb

I don't know if it was already defined in Delphi with its TMemoryStatusEx structure or not (it would be based on the MEMORYSTATUSEX Windows API.)

The fields you need are ullTotalPhys and ullAvailPhys . They are unsigned 64-bit integers.

I forgot, it was only supported by Windows> = 2000, but that should no longer be a problem.

+15
source

@Bill
You need to use GlobalMemoryStatusEx. This is not ideal, but it is better than GlobalMemoryStatus. How? With GlobalMemoryStatus, on a 4 GB computer with Win32, a 32-bit application only shows 2 GB. Using GlobalMemoryStatusEx, 3 GB will be installed in the same application. A little closer to the truth!

This code works the same as in Delphi XE (and above):

 uses Windows; function GetSystemMem: string; { Returns installed RAM (as viewed by your OS) in GB, with 2 decimals } VAR MS_Ex : MemoryStatusEx; begin FillChar (MS_Ex, SizeOf(MemoryStatusEx), #0); MS_Ex.dwLength := SizeOf(MemoryStatusEx); GlobalMemoryStatusEx (MS_Ex); Result:= Real2Str(MS_Ex.ullTotalPhys / GB, 2)+ ' GB'; end; 

Please note that using some API functions will probably never give you the TOTAL amount if this amount exceeds 3 GB and the OS Win 32. Why? Because Windows32 itself cannot "see" all the memory! You need to access the BIOS directly and read the hardware values ​​there. HOWEVER, in some cases this may not be necessary for this: why bother to show that your computer has 4 GB of RAM, if only 3 are available? What I did IN MY CASE, I changed the message:

Installed RAM: 3 GB (or more)

from

Available RAM: 3 GB

Again, I don't know if this is appropriate in your case.

+2
source

Source: https://habr.com/ru/post/899865/


All Articles