summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAndré Nusser <andre.nusser@googlemail.com>2016-07-16 17:27:08 +0200
committerAndré Nusser <andre.nusser@googlemail.com>2016-07-16 17:57:28 +0200
commit973d411598958d968226ed878d9426f23e8f7cbf (patch)
tree07650d2f71450ee83327a2ab8c5631cf7cf3a742 /src
parent591e87c767dda059295e497ae17a499dd3e1c830 (diff)
Memchecker code for OS X.
Diffstat (limited to 'src')
-rw-r--r--src/memchecker.cc16
1 files changed, 15 insertions, 1 deletions
diff --git a/src/memchecker.cc b/src/memchecker.cc
index 6d66965..2bdbf34 100644
--- a/src/memchecker.cc
+++ b/src/memchecker.cc
@@ -30,6 +30,11 @@
#if DG_PLATFORM == DG_PLATFORM_LINUX
#include <sys/sysinfo.h>
+#elif DG_PLATFORM == DG_PLATFORM_OSX
+#include <mach/vm_statistics.h>
+#include <mach/mach_types.h>
+#include <mach/mach_init.h>
+#include <mach/mach_host.h>
#endif
#include <sndfile.h>
@@ -58,7 +63,16 @@ uint64_t MemChecker::calcFreeMemory() const
GlobalMemoryStatusEx(&status);
free_memory = status.ullAvailPhys;
#elif DG_PLATFORM == DG_PLATFORM_OSX
- // TODO
+ vm_size_t page_size;
+ vm_statistics64_data_t vm_stats;
+ mach_port_t mach_port = mach_host_self();
+ mach_msg_type_number_t count = sizeof(vm_stats) / sizeof(natural_t);
+
+ if (KERN_SUCCESS == host_page_size(mach_port, &page_size) &&
+ KERN_SUCCESS == host_statistics64(mach_port, HOST_VM_INFO, (host_info64_t)&vm_stats, &count))
+ {
+ free_memory = (uint64_t)vm_stats.free_count * (uint64_t)page_size;
+ }
#elif DG_PLATFORM == DG_PLATFORM_UNIX
// TODO
#endif