-
Notifications
You must be signed in to change notification settings - Fork 1
/
MemoryStatus.cpp
49 lines (43 loc) · 978 Bytes
/
MemoryStatus.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#include "stdafx.h"
#include "MemoryStatus.h"
#define WIN32_LEAN_AND_MEAN
#define NOMINMAX
#include <windows.h>
namespace rde
{
MemoryStatus::MemoryStatus()
: totalFree(0),
largestFree(0),
totalReserved(0),
totalCommited(0)
{
}
MemoryStatus MemoryStatus::GetCurrent()
{
MemoryStatus status;
memset(&status, 0, sizeof(MemoryStatus));
MEMORY_BASIC_INFORMATION info;
unsigned char* address(0);
SIZE_T bytesInfo = ::VirtualQuery(address, &info, sizeof(info));
while (bytesInfo != 0)
{
if (info.State & MEM_FREE)
{
status.totalFree += info.RegionSize;
if (info.RegionSize > status.largestFree)
status.largestFree = info.RegionSize;
}
else
{
if (info.State & MEM_RESERVE)
status.totalReserved += info.RegionSize;
if (info.State & MEM_COMMIT)
status.totalCommited += info.RegionSize;
}
address += info.RegionSize;
memset(&info, 0, sizeof(info));
bytesInfo = ::VirtualQuery(address, &info, sizeof(info));
}
return status;
}
}