forked from vpinball/vpinball
-
Notifications
You must be signed in to change notification settings - Fork 0
/
MemoryStatus.cpp
48 lines (42 loc) · 946 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
#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 = {};
MEMORY_BASIC_INFORMATION info;
unsigned char* address(nullptr);
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;
}
}