Re: 64-bit problem with VM statistics
Re: 64-bit problem with VM statistics
- Subject: Re: 64-bit problem with VM statistics
- From: William Kucharski <email@hidden>
- Date: Wed, 1 Jun 2005 14:31:51 -0600
There's definitely something weird going on in your universe.
I just compiled and ran this test program:
#include <mach/vm_types.h>
#include <mach/mach_types.h>
#include <sys/types.h>
unsigned long long GetFreeMem()
{
natural_t mac_pagesize;
vm_statistics_data_t vm_stat;
mach_port_t host_priv_port, host_port;
mach_msg_type_number_t host_count;
kern_return_t kern_error;
unsigned long long FreeMem;
// Get host machine information
mach_port_t get_host_priv()
{
return(mach_host_self());
}
mach_port_t get_host_port()
{
return(mach_host_self());
}
// Get total system-wide memory usage structure
host_priv_port = get_host_priv();
host_port = get_host_port();
host_count = sizeof(vm_stat)/sizeof(integer_t);
kern_error = host_statistics(host_priv_port, HOST_VM_INFO,
(host_info_t)&vm_stat, &host_count);
if (kern_error != KERN_SUCCESS)
{
mach_error("host_info", kern_error);
exit(1);
}
host_page_size(host_port, &mac_pagesize);
FreeMem = ((unsigned long long) vm_stat.free_count) * mac_pagesize;
FreeMem &= 0xFFFFFFFFFFFFFFC0ull;
return(FreeMem);
}
main()
{
unsigned long long free = GetFreeMem();
printf("Free memory: %llu bytes (%llu M)\n", free, free /
(1024*1024));
}
On my dual 2 GHz G5:
$ uname -a
Darwin g5 8.1.0 Darwin Kernel Version 8.1.0: Tue May 10 18:16:08 PDT
2005; root:xnu-792.1.5.obj~4/RELEASE_PPC Power Macintosh powerpc
I have 4GB of RAM installed.
$ gcc -v
gcc -v
Reading specs from /usr/lib/gcc/powerpc-apple-darwin8/4.0.0/specs
Configured with: /private/var/tmp/gcc/gcc-4061.obj~8/src/configure --
disable-checking --prefix=/usr --mandir=/share/man --enable-
languages=c,objc,c++,obj-c++ --program-transform-name=/^[cg][^+.-]*$/
s/$/-4.0/ --with-gxx-include-dir=/include/gcc/darwin/4.0/c++ --
build=powerpc-apple-darwin8 --host=powerpc-apple-darwin8 --
target=powerpc-apple-darwin8
Thread model: posix
gcc version 4.0.0 20041026 (Apple Computer, Inc. build 4061)
$ gcc i.c
[ harmless warnings from gcc deleted here ]
$ ./a.out
Free memory: 3573673984 bytes (3408 M)
William Kucharski
email@hidden
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Darwin-kernel mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden