Archive: how to get the physical memory size


how to get the physical memory size
how to get the system's physical memory size in the nsis script? Please tell me,thank you!


http://nsis.sourceforge.net/HwInfo_plug-in


thank you!,but the value is incorrect.My computer is 32bit windowsXP OS,4096MB physical memory.but use:

Section "Silent MakeNSIS"
HwInfo::GetSystemMemory
StrCpy $R0 $0
MessageBox MB_OK "You have $0MB of RAM"

SectionEnd

-------------
get the value 2048MB


On 32 bits WinXP, the virtual address space of processes and applications is limited to 2 GB, unless the process is image_file_large_address_aware and the /3GB flag is set in boot.ini. http://msdn.microsoft.com/en-us/wind...dware/gg487508
If you don't have the 3GB option enabled, there's probably no need to "find" the full 4GB because no single process will be able to address more than 2GB anyway. If you do have the option enabled, and NSIS doesn't support large virtual address space (I don't know if this is the case), you'll probably have to create and execute a new process that does support it, and then have that report back to NSIS.


I find in msdn ,it says use "GlobalMemoryStatusEx" instead of "GlobalMemoryStatus"


void CHardwareInfo::GetTotalSystemMemory( int &sysMem )
{
MEMORYSTATUS memorystatus;
GlobalMemoryStatus( &memorystatus );
sysMem = (int)( ceil( memorystatus.dwTotalPhys / 1048576.f ) );
}
-----------------------
above is the hwinfo soure,the follow is msdn article:

How to use the API to obtain the total physical memory value
To retrieve the most accurate value that is under program control, developers should follow these steps:
1.Call the GlobalMemoryStatusEx function.
2.Query the ullAvailPhys member of the MEMORYSTATUSEX structure.
The components use either the GlobalMemoryStatusEx function or the same kernel technique that is used by the GlobalMemoryStatusEx function to calculate the total physical memory on a computer. To programmatically obtain this value, query the ullAvailPhys member of the MEMORYSTATUSEX structure passed as input to the GlobalMemoryStatusEx function.