Skip to content

RAM usage calculation. #165

Answered by aristocratos
jokerekv2 asked this question in Q&A
Discussion options

You must be logged in to vote

@jokerekv2

Hi, I'm assuming you mean for linux?

Memory stats are read from /proc/meminfo.
But since /proc/meminfo doesn't provide a "used" metric, it's calculated from total memory - available memory.
So "used memory" = "non available memory".
Haven't look at how htop calculates this but the current calculation is what made most sense to me.

The code in question:

//? Read memory info from /proc/meminfo
ifstream meminfo(Shared::procPath / "meminfo");
if (meminfo.good()) {
bool got_avail = false;
for (string label; meminfo >> label;) {
if (label == "MemFree:") {
meminfo >> mem.stats.at("free"

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by aristocratos
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants