forked from Snapchat/KeyDB
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmeminfo.cpp
More file actions
33 lines (30 loc) · 689 Bytes
/
meminfo.cpp
File metadata and controls
33 lines (30 loc) · 689 Bytes
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
#include <string>
#include <fstream>
#include <limits>
static size_t getMemKey(std::string key) {
# ifdef __linux__
std::string token;
std::ifstream f("/proc/meminfo");
while (f >> token) {
if (token == key) {
size_t mem_val;
if (f >> mem_val) {
return mem_val * 1024; // values are in kB
} else {
return 0;
}
f.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
}
}
return 0;
# else
(void)key;
return 0;
# endif
}
size_t getMemAvailable() {
return getMemKey("MemAvailable:");
}
size_t getMemTotal() {
return getMemKey("MemTotal:");
}