Windows下VC获取内存使用率
#pragma once
#include <winsock2.h>
class CMemoryMgr {
public:
MEMORYSTATUSEX m_memoryStatus = { 0 };
BOOL GetMemoryUsedInfo()
{
BOOL bRet = FALSE;
MEMORYSTATUSEX statex = {0};
statex.dwLength = sizeof(statex);
bRet = GlobalMemoryStatusEx(&statex);
if (bRet)
{
memcpy(&m_memoryStatus, &statex, sizeof(m_memoryStatus));
}
return bRet;
}
void Print()
{
std::cout << m_memoryStatus.ullAvailPageFile << "," << m_memoryStatus.ullTotalPageFile << std::endl;
std::cout << m_memoryStatus.ullAvailPhys << "," << m_memoryStatus.ullTotalPhys << std::endl;
std::cout << m_memoryStatus.ullAvailVirtual << "," << m_memoryStatus.ullTotalVirtual << std::endl;
std::cout << "==============" << std::endl;
}
};