Patch get_total_memory() for freebsd compatibility (#172)

This commit is contained in:
David Steele 2017-09-25 16:55:15 -04:00 committed by Sebastian Meßmer
parent 3d52f6a8c4
commit 18788bc3f8
1 changed files with 2 additions and 2 deletions

View File

@ -8,13 +8,13 @@ namespace cpputils{
namespace system {
uint64_t get_total_memory() {
uint64_t mem;
#ifdef __APPLE__
#if defined(__APPLE__)
size_t size = sizeof(mem);
int result = sysctlbyname("hw.memsize", &mem, &size, nullptr, 0);
if (0 != result) {
throw std::runtime_error("sysctlbyname syscall failed");
}
#elif __linux__ || __FreeBSD__
#elif defined(__linux__) || defined(__FreeBSD__)
long numRAMPages = sysconf(_SC_PHYS_PAGES);
long pageSize = sysconf(_SC_PAGESIZE);
mem = numRAMPages * pageSize;