• 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: R: Running out of VM
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: R: Running out of VM


  • Subject: Re: R: Running out of VM
  • From: Alastair Houghton <email@hidden>
  • Date: Sun, 25 Dec 2005 11:17:04 +0000

On 23 Dec 2005, at 09:04, Markus Hitter wrote:

Am 23.12.2005 um 05:25 schrieb Phill Kelley:

The documentation for NSAllocateObject says "Returns nil on failure".

I would have thought that running out of VM constituted a "failure".

Obviously, object allocation doesn't work as documented. Time to file a Radar.

The only workaround I can think of, is to try to allocate memory using the regular malloc() first, then to relase this chunk and to allocate the real object according to the result. A malloc() of length+1024 bytes should be enough for all situations.

That won't necessarily work... many platforms nowadays do lazy allocation of backing store, so if the problem is running out of actual memory rather than virtual address space, you'll often find that malloc() will happily allocate and return a pointer, and then your program will crash when it tries to write to it because the system can't get any more pages.

I don't know whether OS X does lazy allocation or not. AFAIK both Linux and Windows do, and it certainly wouldn't surprise me if OS X did as well.

Anyway, I don't think it's worth fussing too much about running out of RAM on a modern system with lots of RAM and disk space. Unless your program is going to e.g. control an aeroplane or a nuclear reactor (in which case you shouldn't be using OS X---at the very least you're breaching the license agreement), the fact is that the consequences of your program failing are probably less severe than other problems that the machine will suffer elsewhere. Given that fact, the best thing most programs can do is exit as fast as possible (there is an argument for trying to save any modified data to some sort of recovery file, but only if this can be done quickly and without allocating memory).

There are some notable exceptions; obviously, programs that might have to deal with very large data sets may need to have some sort of mechanism in place to deal with this problem, but relying on e.g. malloc() to return NULL isn't sufficient I don't think.

Finally, if you *really* want to catch the allocation failure, you should be able to handle the SIGTRAP signal, or alternatively use the Mach functions to handle exceptions. It's a processor exception, so an NS_DURING, @try or C++ try won't catch it.

Kind regards,

Alastair.

--
http://www.alastairs-place.net


_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden
  • Follow-Ups:
    • Re: R: Running out of VM
      • From: Jonathan del Strother <email@hidden>
References: 
 >Re: R: Running out of VM (From: Phill Kelley <email@hidden>)
 >Re: R: Running out of VM (From: Markus Hitter <email@hidden>)

  • Prev by Date: Re: Replacement for openUntitledDocumentOfType:display:?
  • Next by Date: Re: R: Running out of VM
  • Previous by thread: Re: R: Running out of VM
  • Next by thread: Re: R: Running out of VM
  • Index(es):
    • Date
    • Thread