64-bit problem with VM statistics
64-bit problem with VM statistics
- Subject: 64-bit problem with VM statistics
- From: Tony Scaminaci <email@hidden>
- Date: Tue, 31 May 2005 14:28:31 -0500
The following calculation of free memory (in bytes) works correctly on 32-bit platforms. On 64-bit systems (Tiger + G5),
the result is a horrendously huge number rather than what is expected. I'm sure this is one of the conversion issues covered
in the 64-bit transition guide (which I've read over multiple times already) but I can't seem to nail down the right
way to do this calculation for both 32 and 64-bit systems.
vm_size_t mac_pagesize;
unsigned long long FreeMem; // Free real (physical) memory in bytes
.
.
.
FreeMem = ((unsigned long long) vm_stat.free_count) * mac_pagesize; // Calculate total free memory in bytes
where "vm_stat.free_count" is the number of free memory pages and remains a 32-bit quantity according to the Darwin 8.1 source
code for the "vm_stat" system call. "Mac_pagesize" is always 4096.
I've considered the following line as a possible fix:
FreeMem = (unsigned long long) (vm_stat.free_count * mac_pagesize);
I'm not sure this is correct either because the multiplication could result in a 64-bit number prior to the type conversion on systems
with a large amount of ram installed (> ~ 4.5 GB). What is the proper way to typecast the number of free memory pages to the number of bytes so that the result will be correct on both 32 and 64-bit platforms?
Thanks,
Tony
_______________________________________________
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