Total Physical Memory
Total Physical Memory
- Subject: Total Physical Memory
- From: Rohitash Panda <email@hidden>
- Date: Wed, 25 Feb 2009 19:46:17 +0530
- Organization: Oracle Corporation
Hi,
I got a couple of ways to figure out the total physical memory
available on the system . The sample code is as below :
--
#include <sys/sysctl.h>
#include <stdio.h>
#include <mach/mach.h>
#include <unistd.h>
int
main() {
int mib[2];
uint64_t memsize;
size_t len;
#if defined HW_PHYSMEM
mib[0] = CTL_HW;
mib[1] = HW_MEMSIZE;
len = sizeof(memsize);
sysctl(mib, 2, &memsize, &len, NULL, 0);
#else
size_t pagesize;
mach_port_t sls_port = mach_host_self();
mach_msg_type_number_t vmCount = HOST_VM_INFO_COUNT;
vm_statistics_data_t vm;
kern_return_t error;
error = host_statistics(sls_port , HOST_VM_INFO , (host_info_t)
&vm, &vmCount);
pagesize = (unsigned long)sysconf(_SC_PAGESIZE);
memsize = (vm.wire_count + vm.active_count + vm.inactive_count +
vm.free_count + vm.zero_fill_count ) * pagesize;
#endif
printf("- memsize = i \n", memsize);
return 0;
}
--
So , as you can see , I want to use the sysctl interface by default and
fall-back on the host_statistics() call only when the sysctl interface
isn't available .
What are the right defines for checking that the sysctl interface is
available ?
Since I get more accurate results with the sysctl interface , is it
fine to use the sysctl() over the host_statistics() interface ?
Appreciate your comments/feedback.
Thanks.
--
Rohitash
Panda | Database Platform Specific Development
Server
Technologies
|
Oracle
is committed to developing practices and products that help protect the
environment
|
|
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Darwin-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden