[comp.sys.mac.programmer] Protecting your System Heap space

Martin@cs.uchicago.edu (03/16/91)

Suppose I have a utility that resides in the system heap.  This utility
will need to allocate more or less memory in the course of normal
operation, so I give it a 'sysz' resource to increase the size of the
system heap.

Unfortunately, it's possible that at the time my utility needs the space,
it will have been stolen or fragmented by another such utility.

How do I protect myself from this?  One technique I can think of is to
immediately allocate a handle of the 'sysz' size upon initialization.
Now, whenever the utility needs space it shrinks that handle size by the
required amount.  Unfortunately, if I can subsequently give that space up
I may not be able to expand the handle size by that amount due to
fragmentation.  So this technique doesn't seem like it would work.

This must be common problem that anything without its own heap must solve.
Am I missing something obvious?

Charles Martin // martin@cs.uchicago.edu