增加当前进程内存使用量获取类,用于内存控制时使用

This commit is contained in:
lovelyyoung 2020-05-16 09:42:28 +08:00
parent 4375ccfdc3
commit e74350d1c5
2 changed files with 21 additions and 0 deletions

View File

@ -0,0 +1,14 @@
#include "GetMemoryUsage.h"
#include <windows.h>
#include <Psapi.h>
int GetMemoryUsage::CurrentProcessMemoryInfo()
{
HANDLE handle = GetCurrentProcess();
PROCESS_MEMORY_COUNTERS_EX pmc = { 0 };
int a = sizeof(pmc);
if (!GetProcessMemoryInfo(handle, (PROCESS_MEMORY_COUNTERS*)&pmc, sizeof(pmc)))
return -1;
else
return pmc.PeakPagefileUsage / 1024 / 1024;
}

View File

@ -0,0 +1,7 @@
#pragma once
class GetMemoryUsage
{
public:
static int CurrentProcessMemoryInfo();
};