Re: determining free memory
Re: determining free memory
- Subject: Re: determining free memory
- From: Jens Alfke <email@hidden>
- Date: Sat, 16 Feb 2008 08:30:24 -0800
On 16 Feb '08, at 4:27 AM, Ruotger Skupin wrote:
my app uses a lot of memory and I am looking for a Tiger compatible
way to determine that memory (or address space) is running low
*before* the first [[XXX alloc] init] returns nil.
There is a system call that tells how much address space you're using
(I don't know the name offhand), but that's only part of the story. If
address space is fragmented, an allocation that's bigger than any
available free space will fail, even though there's enough total free
space.
For small allocations (a few k or less) it's even more complex,
because malloc sub-allocates those blocks out of larger blocks grabbed
from VM, and keeps its own free lists. So a small allocation usually
won't allocate new address space at all, if there's a big enough free
block in an already-allocated malloc zone.
So in general there's no practical way to preflight memory
allocations. The best you can do is watch the overall amount of
address space in use and warn the user when it starts to get large.
(But of course you should #ifdef that out in a 64-bit build!)
—Jens_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden