#include<psapi.h>
void showMemoryInfo() {
HANDLE handle = GetCurrentProcess();
PROCESS_MEMORY_COUNTERS pmc;
GetProcessMemoryInfo(handle, &pmc, sizeof(pmc));
std::string strs;
LOG_PRINT("memory used %d M/ %d M + usage %d M/ %d M",
pmc.WorkingSetSize / 1024 / 1024,
pmc.PeakWorkingSetSize / 1024 / 1024,
pmc.PagefileUsage / 1024 / 1024,
pmc.PeakPagefileUsage / 1024 / 1024);
}
PROCESS_MEMORY_COUNTERS结构体内容如下:
typedef struct _PROCESS_MEMORY_COUNTERS {
DWORD cb;
DWORD PageFaultCount;
SIZE_T PeakWorkingSetSize; //峰值内存使用
SIZE_T WorkingSetSize; //内存使用
SIZE_T QuotaPeakPagedPoolUsage;
SIZE_T QuotaPagedPoolUsage;
SIZE_T QuotaPeakNonPagedPoolUsage;
SIZE_T QuotaNonPagedPoolUsage;
SIZE_T PagefileUsage; //虚拟内存使用
SIZE_T PeakPagefileUsage; //峰值虚拟内存使用
} PROCESS_MEMORY_COUNTERS,
*PPROCESS_MEMORY_COUNTERS;