Path: utzoo!utgpu!jarvis.csri.toronto.edu!rutgers!iuvax!purdue!bu-cs!dartvax!eleazar.dartmouth.edu!earleh From: earleh@eleazar.dartmouth.edu (Earle R. Horton) Newsgroups: comp.sys.mac.programmer Subject: Re: How to indicate Out Of Memory Message-ID: <14215@dartvax.Dartmouth.EDU> Date: 5 Jul 89 17:06:17 GMT References: <9866@brunix.UUCP> Sender: news@dartvax.Dartmouth.EDU Reply-To: earleh@eleazar.dartmouth.edu (Earle R. Horton) Organization: Thayer School of Engineering Lines: 37 In article <9866@brunix.UUCP> man@cs.brown.edu () writes: >I've written a program which allocates memory using NewHandle and >SetHandleSize. I have my own routines UtilNewHandle and >UtilSetHandleSize which call the toolbox routines and then check >MemError() to see if the call succeeded. When I detect an >out-of-memory condition, I'd like to put up an alert box and then >abort. I have two problems: A problem with this approach is that the Toolbox and Operating System need to allocate space in your application's heap, in addition to what you use directly. When you only check for out-of-memory, you run the risk of not having enough of a free memory pool around for many system calls to succeed. How big your pool of free space should be is something you will probably have to determine empirically, but you will need one. One possible solution, since you process memory requests through your own filter routines, is to check the amount for free memory before calling NewHandle and SetHandleSize. If you see that memory is getting low, then you can warn the user with an alert before operation becomes unsafe. If you make sure that the free pool is always big enough, then you will not get memory-related system errors, and you will have enough memory to put up the alert box. This is more friendly to the user than waiting until memory requests fail before you take action. Another option is to reserve a largish block of memory which can be released if things get tight. You can use a GrowZone procedure to release this block, thereby making the space available to system routines. When the GrowZone procedure is called, then you release the block, assuring that the current memory request succeeds, but you also set a global variable to indicate that future requests have a chance of failure. Earle R. Horton "People forget how fast you did a job, but they remember how well you did it." Salada Tag Lines