Fix: check_memory tool shows incorrect memory size on windows

On a PC with >4GB of RAM, check_memory utility returns
an incorrect amount of RAM:

MEMORY OK - 100% free | memory=4096MB;;;0;4096

This patch uses GlobalMemoryStatusEx instead of GlobalMemoryStatus
[https://msdn.microsoft.com/en-us/library/windows/desktop/aa366586%28v=vs.85%29.aspx]

Following patch output of check_memory is as follows:

MEMORY OK - 32.4873% free | memory=5312MB;;;0;16351

fixes #8559

Signed-off-by: Gunnar Beutner <gunnar@beutner.name>
This commit is contained in:
Paul Richards 2015-03-01 21:23:36 +00:00 committed by Gunnar Beutner
parent 2d65489f3a
commit 7ca3a3c5e9
1 changed files with 9 additions and 7 deletions

View File

@ -36,7 +36,7 @@ static BOOL debug = FALSE;
struct printInfoStruct
{
threshold warn, crit;
DWORD tRam, aRam;
DWORDLONG tRam, aRam;
Bunit unit = BunitMB;
};
@ -213,16 +213,18 @@ int check_memory(printInfoStruct& printInfo)
if (debug)
wcout << L"Accessing memory statistics via MemoryStatus" << endl;
_MEMORYSTATUS *pMemBuf = new _MEMORYSTATUS;
_MEMORYSTATUSEX *pMemBuf = new _MEMORYSTATUSEX;
GlobalMemoryStatus(pMemBuf);
pMemBuf->dwLength = sizeof(*pMemBuf);
printInfo.tRam = round(pMemBuf->dwTotalPhys / pow(1024.0, printInfo.unit));
printInfo.aRam = round(pMemBuf->dwAvailPhys / pow(1024.0, printInfo.unit));
GlobalMemoryStatusEx(pMemBuf);
printInfo.tRam = round(pMemBuf->ullTotalPhys / pow(1024.0, printInfo.unit));
printInfo.aRam = round(pMemBuf->ullAvailPhys / pow(1024.0, printInfo.unit));
if (debug)
wcout << L"Found pMemBuf->dwTotalPhys: " << pMemBuf->dwTotalPhys << endl
<< L"Found pMemBuf->dwAvailPhys: " << pMemBuf->dwAvailPhys << endl;
wcout << L"Found pMemBuf->dwTotalPhys: " << pMemBuf->ullTotalPhys << endl
<< L"Found pMemBuf->dwAvailPhys: " << pMemBuf->ullAvailPhys << endl;
delete pMemBuf;