Skip navigation.
 
mlRe: determining free memory
FROM : Jens Alfke
DATE : Sat Feb 16 17:30:24 2008

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_removed>)

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:
http://lists.apple.com/mailman/options/cocoa-dev/<email_removed>

This email sent to <email_removed>

Related mailsAuthorDate
mldetermining free memory Ruotger Skupin Feb 16, 13:27
mlRe: determining free memory Jens Alfke Feb 16, 17:30
mlRe: determining free memory Ruotger Skupin Feb 17, 18:39