Re: Total Physical Memory
Re: Total Physical Memory
- Subject: Re: Total Physical Memory
- From: Terry Lambert <email@hidden>
- Date: Wed, 25 Feb 2009 16:47:28 -0800
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".
-- Terry
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>
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
<green-for-email-sig_0.gif>
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.
Unix-porting mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden
_______________________________________________
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