diff options
-rw-r--r-- | src/memchecker.cc | 16 |
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 |