From 973d411598958d968226ed878d9426f23e8f7cbf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Nusser?= Date: Sat, 16 Jul 2016 17:27:08 +0200 Subject: Memchecker code for OS X. --- src/memchecker.cc | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) (limited to 'src') 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 +#elif DG_PLATFORM == DG_PLATFORM_OSX +#include +#include +#include +#include #endif #include @@ -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 -- cgit v1.2.3