-
-
Notifications
You must be signed in to change notification settings - Fork 86
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
7 changed files
with
172 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
// infoware - C++ System information Library | ||
// | ||
// Written in 2016 by nabijaczleweli <[email protected]> and ThePhD <[email protected]> | ||
// | ||
// To the extent possible under law, the author(s) have dedicated all copyright and related | ||
// and neighboring rights to this software to the public domain worldwide. This software is | ||
// distributed without any warranty. | ||
// | ||
// You should have received a copy of the CC0 Public Domain Dedication along with this software. | ||
// If not, see <http://creativecommons.org/publicdomain/zero/1.0/> | ||
|
||
|
||
#include "infoware/system.hpp" | ||
#include <iostream> | ||
|
||
|
||
int main() { | ||
std::cout << iware::system::memory().physical_available << '\n'; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
// infoware - C++ System information Library | ||
// | ||
// Written in 2016 by nabijaczleweli <[email protected]> and ThePhD <[email protected]> | ||
// | ||
// To the extent possible under law, the author(s) have dedicated all copyright and related | ||
// and neighboring rights to this software to the public domain worldwide. This software is | ||
// distributed without any warranty. | ||
// | ||
// You should have received a copy of the CC0 Public Domain Dedication along with this software. | ||
// If not, see <http://creativecommons.org/publicdomain/zero/1.0/> | ||
|
||
|
||
#include "infoware/system.hpp" | ||
#include <iostream> | ||
|
||
|
||
int main() { | ||
std::cout << iware::system::memory().physical_total << '\n'; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
// infoware - C++ System information Library | ||
// | ||
// Written in 2016 by nabijaczleweli <[email protected]> and ThePhD <[email protected]> | ||
// | ||
// To the extent possible under law, the author(s) have dedicated all copyright and related | ||
// and neighboring rights to this software to the public domain worldwide. This software is | ||
// distributed without any warranty. | ||
// | ||
// You should have received a copy of the CC0 Public Domain Dedication along with this software. | ||
// If not, see <http://creativecommons.org/publicdomain/zero/1.0/> | ||
|
||
|
||
#include "infoware/system.hpp" | ||
#include <iostream> | ||
|
||
|
||
int main() { | ||
std::cout << iware::system::memory().virtual_available << '\n'; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
// infoware - C++ System information Library | ||
// | ||
// Written in 2016 by nabijaczleweli <[email protected]> and ThePhD <[email protected]> | ||
// | ||
// To the extent possible under law, the author(s) have dedicated all copyright and related | ||
// and neighboring rights to this software to the public domain worldwide. This software is | ||
// distributed without any warranty. | ||
// | ||
// You should have received a copy of the CC0 Public Domain Dedication along with this software. | ||
// If not, see <http://creativecommons.org/publicdomain/zero/1.0/> | ||
|
||
|
||
#include "infoware/system.hpp" | ||
#include <iostream> | ||
|
||
|
||
int main() { | ||
std::cout << iware::system::memory().virtual_total << '\n'; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
// infoware - C++ System information Library | ||
// | ||
// Written in 2016 by nabijaczleweli <[email protected]> and ThePhD <[email protected]> | ||
// | ||
// To the extent possible under law, the author(s) have dedicated all copyright and related | ||
// and neighboring rights to this software to the public domain worldwide. This software is | ||
// distributed without any warranty. | ||
// | ||
// You should have received a copy of the CC0 Public Domain Dedication along with this software. | ||
// If not, see <http://creativecommons.org/publicdomain/zero/1.0/> | ||
|
||
|
||
#ifndef _WIN32 | ||
|
||
|
||
#include "infoware/system.hpp" | ||
#include <fstream> | ||
#include <string> | ||
|
||
|
||
iware::system::memory_t iware::system::memory() noexcept { | ||
std::ifstream meminfo("/proc/meminfo"); | ||
|
||
if(!meminfo.is_open() || !meminfo) | ||
return ret; | ||
|
||
iware::system::memory_t ret; | ||
for(std::string line; std::getline(meminfo, line);) { | ||
const auto colon_id = line.find_first_of(':'); | ||
const auto value = std::strtoul(line.c_str() + colon_id + 1, nullptr) * 1024; | ||
|
||
if(line.find("MemTotal") == 0) | ||
ret.physical_total = value; | ||
else if(line.find("MemAvailable") == 0) | ||
ret.physical_available = value; | ||
else if(line.find("VmallocTotal") == 0) | ||
ret.virtual_total = value; | ||
else if(line.find("VmallocUsed") == 0) | ||
ret.virtual_available = ret.virtual_total - value; | ||
} | ||
|
||
return ret; | ||
} | ||
|
||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
// infoware - C++ System information Library | ||
// | ||
// Written in 2016 by nabijaczleweli <[email protected]> and ThePhD <[email protected]> | ||
// | ||
// To the extent possible under law, the author(s) have dedicated all copyright and related | ||
// and neighboring rights to this software to the public domain worldwide. This software is | ||
// distributed without any warranty. | ||
// | ||
// You should have received a copy of the CC0 Public Domain Dedication along with this software. | ||
// If not, see <http://creativecommons.org/publicdomain/zero/1.0/> | ||
|
||
|
||
#ifdef _WIN32 | ||
|
||
|
||
#include "infoware/system.hpp" | ||
#define WIN32_LEAN_AND_MEAN | ||
#include <windows.h> | ||
|
||
|
||
iware::system::memory_t iware::system::memory() noexcept { | ||
MEMORYSTATUSEX mem; | ||
mem.dwLength = sizeof(mem); | ||
if(!GlobalMemoryStatusEx(&mem)) | ||
return {}; | ||
|
||
return { | ||
mem.ullTotalPhys, | ||
mem.ullAvailPhys, | ||
mem.ullTotalVirtual, | ||
mem.ullAvailVirtual, | ||
}; | ||
} | ||
|
||
|
||
#endif |