• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: determining free memory
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


  • Follow-Ups:
    • Re: determining free memory
      • From: Ruotger Skupin <email@hidden>
References: 
 >determining free memory (From: Ruotger Skupin <email@hidden>)

  • Prev by Date: Re: My sheet leaks
  • Next by Date: Re: Strategies to prevent class name clashes
  • Previous by thread: determining free memory
  • Next by thread: Re: determining free memory
  • Index(es):
    • Date
    • Thread