From 7ca3a3c5e9ed7514e8d0ff9bf63ac669f0066247 Mon Sep 17 00:00:00 2001 From: Paul Richards Date: Sun, 1 Mar 2015 21:23:36 +0000 Subject: [PATCH] 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 --- plugins/check_memory.cpp | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/plugins/check_memory.cpp b/plugins/check_memory.cpp index 1d30f3673..229d5243c 100644 --- a/plugins/check_memory.cpp +++ b/plugins/check_memory.cpp @@ -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;