Patch get_total_memory() for freebsd compatibility (#172)
This commit is contained in:
parent
3d52f6a8c4
commit
18788bc3f8
@ -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;
|
||||
|
Loading…
x
Reference in New Issue
Block a user