Re: querying the system for RAM usage
Re: querying the system for RAM usage
- Subject: Re: querying the system for RAM usage
- From: Brian Bergstrand <email@hidden>
- Date: Sat, 25 Jun 2005 22:05:20 -0500
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
On Jun 25, 2005, at 5:49 PM, nick briggs wrote:
Hello
I am to querying the system for RAM usage by creating a NSTask to
'top' and parsing the output, are we aware of a more elegant
solution / API?
#import <mach/host_info.h>
#import <mach/mach_host.h>
#import <mach/host_priv.h>
vm_statistics_data_t page_info;
mach_msg_type_number_t count;
count = HOST_VM_INFO_COUNT;
kern_return_t kret = host_statistics (mach_host_self(),
HOST_VM_INFO, (host_info_t)&page_info, &count);
if (KERN_SUCCESS == kret) {
(void)page_info.wire_count; // pages in use by the kernel and
drivers (and pages wired by root applications -- should be minimal)
(void)page_info.active_count; // pages in use by applications
(void)page_info.inactive_count; // pages recently used by
applications (file/vm cache)
(void)page_info.free_count; // pages not used
}
You can assume the page size is always 4K, but the correct way is
query the system.
vm_size_t pagesize;
kret = host_page_size (mach_host_self(), &pagesize);
You can also use sysctl on the bsd side to get most if not all of
this info. Also, note that these values are likely to have changed as
soon the call returns, so don't rely on them as hard #'s.
HTH.
Brian Bergstrand
<http://www.bergstrand.org/brian/> PGP Key ID: 0xB6C7B6A2
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.1 (Darwin)
iD8DBQFCvht1edHYW7bHtqIRAsurAKDP9lbaPCW4lfiMzBCH67OWjn5qsgCfZcHl
CA9HUpzcCW8MXFN88ticeQQ=
=XpsX
-----END PGP SIGNATURE-----
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden