OpenBSD has a custom sysctl for physical memory.
This commit is contained in:
parent
92594e08d4
commit
242c770fe5
|
@ -20,7 +20,7 @@
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <sys/mman.h>
|
#include <sys/mman.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#if defined __APPLE__ || defined __FreeBSD__
|
#if defined __APPLE__ || defined __FreeBSD__ || defined __OpenBSD__
|
||||||
#include <sys/sysctl.h>
|
#include <sys/sysctl.h>
|
||||||
#else
|
#else
|
||||||
#include <sys/sysinfo.h>
|
#include <sys/sysinfo.h>
|
||||||
|
@ -253,7 +253,7 @@ size_t MemPhysical()
|
||||||
memInfo.dwLength = sizeof(MEMORYSTATUSEX);
|
memInfo.dwLength = sizeof(MEMORYSTATUSEX);
|
||||||
GlobalMemoryStatusEx(&memInfo);
|
GlobalMemoryStatusEx(&memInfo);
|
||||||
return memInfo.ullTotalPhys;
|
return memInfo.ullTotalPhys;
|
||||||
#elif defined __APPLE__ || defined __FreeBSD__
|
#elif defined __APPLE__ || defined __FreeBSD__ || defined __OpenBSD__
|
||||||
int mib[2];
|
int mib[2];
|
||||||
size_t physical_memory;
|
size_t physical_memory;
|
||||||
mib[0] = CTL_HW;
|
mib[0] = CTL_HW;
|
||||||
|
@ -261,6 +261,8 @@ size_t MemPhysical()
|
||||||
mib[1] = HW_MEMSIZE;
|
mib[1] = HW_MEMSIZE;
|
||||||
#elif defined __FreeBSD__
|
#elif defined __FreeBSD__
|
||||||
mib[1] = HW_REALMEM;
|
mib[1] = HW_REALMEM;
|
||||||
|
#elif defined __OpenBSD__
|
||||||
|
mib[1] = HW_PHYSMEM;
|
||||||
#endif
|
#endif
|
||||||
size_t length = sizeof(size_t);
|
size_t length = sizeof(size_t);
|
||||||
sysctl(mib, 2, &physical_memory, &length, NULL, 0);
|
sysctl(mib, 2, &physical_memory, &length, NULL, 0);
|
||||||
|
|
Loading…
Reference in New Issue