diff --git a/Library/MeasureMemory.cpp b/Library/MeasureMemory.cpp index f2be5cdd..98afa4d6 100644 --- a/Library/MeasureMemory.cpp +++ b/Library/MeasureMemory.cpp @@ -27,6 +27,10 @@ CMeasureMemory::CMeasureMemory(CMeterWindow* meterWindow, const WCHAR* name) : CMeasure(meterWindow, name), m_Total(false) { + MEMORYSTATUSEX stat; + stat.dwLength = sizeof(MEMORYSTATUSEX); + GlobalMemoryStatusEx(&stat); + m_MaxValue = (double)(__int64)(stat.ullTotalPageFile + stat.ullTotalPhys); } /* @@ -43,15 +47,12 @@ CMeasureMemory::~CMeasureMemory() */ void CMeasureMemory::UpdateValue() { - MEMORYSTATUSEX stat; - stat.dwLength = sizeof(MEMORYSTATUSEX); - GlobalMemoryStatusEx(&stat); - if (m_Total) - { - m_Value = (double)(__int64)(stat.ullTotalPageFile + stat.ullTotalPhys); - } - else + if (!m_Total) { + MEMORYSTATUSEX stat; + stat.dwLength = sizeof(MEMORYSTATUSEX); + GlobalMemoryStatusEx(&stat); + m_Value = (double)(__int64)(stat.ullTotalPageFile + stat.ullTotalPhys - stat.ullAvailPageFile - stat.ullAvailPhys); } } @@ -62,13 +63,13 @@ void CMeasureMemory::UpdateValue() */ void CMeasureMemory::ReadOptions(CConfigParser& parser, const WCHAR* section) { + double oldMaxValue = m_MaxValue; CMeasure::ReadOptions(parser, section); + m_MaxValue = oldMaxValue; m_Total = (1 == parser.ReadInt(section, L"Total", 0)); - - MEMORYSTATUSEX stat; - stat.dwLength = sizeof(MEMORYSTATUSEX); - GlobalMemoryStatusEx(&stat); - m_MaxValue = (double)(__int64)(stat.ullTotalPageFile + stat.ullTotalPhys); + if (m_Total) + { + m_Value = m_MaxValue; + } } - diff --git a/Library/MeasurePhysicalMemory.cpp b/Library/MeasurePhysicalMemory.cpp index caf7e86d..a3d3f334 100644 --- a/Library/MeasurePhysicalMemory.cpp +++ b/Library/MeasurePhysicalMemory.cpp @@ -27,6 +27,10 @@ CMeasurePhysicalMemory::CMeasurePhysicalMemory(CMeterWindow* meterWindow, const WCHAR* name) : CMeasure(meterWindow, name), m_Total(false) { + MEMORYSTATUSEX stat; + stat.dwLength = sizeof(MEMORYSTATUSEX); + GlobalMemoryStatusEx(&stat); + m_MaxValue = (double)(__int64)stat.ullTotalPhys; } /* @@ -43,15 +47,12 @@ CMeasurePhysicalMemory::~CMeasurePhysicalMemory() */ void CMeasurePhysicalMemory::UpdateValue() { - MEMORYSTATUSEX stat; - stat.dwLength = sizeof(MEMORYSTATUSEX); - GlobalMemoryStatusEx(&stat); - if (m_Total) - { - m_Value = (double)(__int64)stat.ullTotalPhys; - } - else + if (!m_Total) { + MEMORYSTATUSEX stat; + stat.dwLength = sizeof(MEMORYSTATUSEX); + GlobalMemoryStatusEx(&stat); + m_Value = (double)(__int64)(stat.ullTotalPhys - stat.ullAvailPhys); } } @@ -62,13 +63,14 @@ void CMeasurePhysicalMemory::UpdateValue() */ void CMeasurePhysicalMemory::ReadOptions(CConfigParser& parser, const WCHAR* section) { + double oldMaxValue = m_MaxValue; CMeasure::ReadOptions(parser, section); + m_MaxValue = oldMaxValue; m_Total = (1 == parser.ReadInt(section, L"Total", 0)); - - MEMORYSTATUSEX stat; - stat.dwLength = sizeof(MEMORYSTATUSEX); - GlobalMemoryStatusEx(&stat); - m_MaxValue = (double)(__int64)stat.ullTotalPhys; + if (m_Total) + { + m_Value = m_MaxValue; + } } diff --git a/Library/MeasureVirtualMemory.cpp b/Library/MeasureVirtualMemory.cpp index 64e2878d..324c74b7 100644 --- a/Library/MeasureVirtualMemory.cpp +++ b/Library/MeasureVirtualMemory.cpp @@ -27,6 +27,10 @@ CMeasureVirtualMemory::CMeasureVirtualMemory(CMeterWindow* meterWindow, const WCHAR* name) : CMeasure(meterWindow, name), m_Total(false) { + MEMORYSTATUSEX stat; + stat.dwLength = sizeof(MEMORYSTATUSEX); + GlobalMemoryStatusEx(&stat); + m_MaxValue = (double)(__int64)stat.ullTotalPageFile; } /* @@ -43,15 +47,12 @@ CMeasureVirtualMemory::~CMeasureVirtualMemory() */ void CMeasureVirtualMemory::UpdateValue() { - MEMORYSTATUSEX stat; - stat.dwLength = sizeof(MEMORYSTATUSEX); - GlobalMemoryStatusEx(&stat); - if (m_Total) - { - m_Value = (double)(__int64)stat.ullTotalPageFile; - } - else + if (!m_Total) { + MEMORYSTATUSEX stat; + stat.dwLength = sizeof(MEMORYSTATUSEX); + GlobalMemoryStatusEx(&stat); + m_Value = (double)(__int64)(stat.ullTotalPageFile - stat.ullAvailPageFile); } } @@ -62,13 +63,14 @@ void CMeasureVirtualMemory::UpdateValue() */ void CMeasureVirtualMemory::ReadOptions(CConfigParser& parser, const WCHAR* section) { + double oldMaxValue = m_MaxValue; CMeasure::ReadOptions(parser, section); + m_MaxValue = oldMaxValue; m_Total = (1 == parser.ReadInt(section, L"Total", 0)); - - MEMORYSTATUSEX stat; - stat.dwLength = sizeof(MEMORYSTATUSEX); - GlobalMemoryStatusEx(&stat); - m_MaxValue = (double)(__int64)stat.ullTotalPageFile; + if (m_Total) + { + m_Value = m_MaxValue; + } }