site_archiver@lists.apple.com Delivered-To: darwin-dev@lists.apple.com -- Terry 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; printf("- memsize = %10i \n", memsize); return 0; } -- Appreciate your comments/feedback. Thanks. -- Rohitash Panda | Database Platform Specific Development Server Technologies _______________________________________________ Do not post admin requests to the list. They will be ignored. Unix-porting mailing list (Unix-porting@lists.apple.com) Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/unix-porting/tlambert%40apple.com _______________________________________________ Do not post admin requests to the list. They will be ignored. Darwin-dev mailing list (Darwin-dev@lists.apple.com) Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/darwin-dev/site_archiver%40lists.appl... Unless your process is the only process running on the system, and the system is in single user mode, knowing how much physical memory is in the system isn't really going to tell you the available physical memory free that you could then use to try and gank all of it out from under any other process that also needs memory. About the only thing going down this path will do is result in your software being labelled "Does Not Play Well With The Other Children". On Feb 25, 2009, at 6:16 AM, Rohitash Panda wrote: 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> 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 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 ? <green-for-email-sig_0.gif> Oracle is committed to developing practices and products that help protect the environment This email sent to tlambert@apple.com This email sent to site_archiver@lists.apple.com