Getting the deviceβs physical memory is simple with sysctl :
int mib [] = { CTL_HW, HW_MEMSIZE }; int64_t value = 0; size_t length = sizeof(value); if(-1 == sysctl(mib, 2, &value, &length, NULL, 0))
VM stats are only a little trickier:
mach_msg_type_number_t count = HOST_VM_INFO_COUNT; vm_statistics_data_t vmstat; if(KERN_SUCCESS != host_statistics(mach_host_self(), HOST_VM_INFO, (host_info_t)&vmstat, &count))
Then you can use the data in vmstat to get the necessary information:
double total = vmstat.wire_count + vmstat.active_count + vmstat.inactive_count + vmstat.free_count; double wired = vmstat.wire_count / total; double active = vmstat.active_count / total; double inactive = vmstat.inactive_count / total; double free = vmstat.free_count / total;
There is also a 64-bit version of the interface.
source share