[comp.sys.mac] A Trivial Suggestion

fdot@sphinx.uchicago.edu (Tom Lippincott) (06/12/87)

     I was trying to make my program hold up under out-of-memory errors,
and found a minor problem with the control manager, which perhaps
could be fixed in the next ROMs.  When I run flat out of memory,
my heap expansion procedure ends up doing a longjmp back to the main
event loop.  If this happens while creating a control, it leaves
the control in the window's control list, but without the proper refcon,
wreaking havoc with the program.
	It seems to me that the control shouldn't be installed until
the control record is finished, to avoid this and similar problems.

					--Tom Lippincott
					..ihnp4!gargoyle!sphinx!fdot

"Just a moment....  Just a moment....  I'm picking up a fault in the AE-35
subunit.  It will go one hundred percent failure within seventy-two hours."

dgold@apple.UUCP (06/15/87)

In article <1968@sphinx.uchicago.edu> fdot@sphinx.UUCP (Tom Lippincott) writes:
>...When I run flat out of memory,
>my heap expansion procedure ends up doing a longjmp back to the main
>event loop...

This is a bad thing to do.  The Memory Manager (and the rest of the Toolbox)
expects to get control back from your GrowZone procedure.  If you unwind
the stack as you are doing, there is no guarantee the system will continue
to operate correctly.  You must signal failure by returning 0 from your
GrowZone, and cope with the error which the Memory Manager returns to its
caller.  In order to prevent failures from Toolbox components which call
SysError when out of memory, you must arrange for your GrowZone to always
have memory available to give up for use by the Toolbox.
-- 
David Goldsmith
Apple Computer, Inc.

AppleLink: GOLDSMITH1
UUCP:  {nsc,dual,sun,voder,ucbvax!mtxinu}!apple!dgold
CSNET: dgold@apple.CSNET, dgold%apple@CSNET-RELAY
BIX: dgoldsmith