Legacy Documentclose button

Important: The information in this document is obsolete and should not be used for new development.

Previous Book Contents Book Index Next

Inside Macintosh: Memory /
Chapter 2 - Memory Manager / Memory Manager Reference
Application-Defined Routines / Purge-Warning Procedures


MyPurgeProc

A purge-warning procedure should have the following form:

PROCEDURE MyPurgeProc (h: Handle);
h
A handle to the block that is about to be purged.
DESCRIPTION
Whenever the Memory Manager needs to purge a block from the application heap, it first calls any application-defined purge-warning procedure that you have installed. The purge-warning procedure can, if necessary, save the contents of that block or otherwise respond to the warning.

Your purge-warning procedure is called during a memory-allocation request. As a result, you should not call any routines that might cause memory to be moved or purged. In particular, if you save the data of the block in a file, the file should already be open when your purge-warning procedure is called, and you should write the data synchronously.

You should not dispose of or change the purgeable status of the block whose handle is passed to your procedure.

To install a purge-warning procedure, you need to assign its address to the purgeProc field of the associated zone header.

Note
If you call the Resource Manager procedure SetResPurge with the parameter TRUE, any existing purge-warning procedure is replaced
by a purge-warning procedure installed by the Resource Manager.
You can execute both warning procedures by calling SetResPurge, saving the existing value of the purgeProc field of the zone
header, and then reinstalling your purge-warning procedure.
Your purge-warning procedure should call the Resource Manager's purge-warning procedure internally.
SPECIAL CONSIDERATIONS
Your purge-warning procedure might be called at a time when the system is attempting to allocate memory and the value in the A5 register is not correct. If your function accesses your application's A5 world or makes any trap calls, you need to set up and later restore the A5 register by calling SetCurrentA5 and SetA5.

Because of the optimizations performed by some compilers, the actual work of the purge-warning procedure and the setting and restoring of the A5 register might have to be placed in separate procedures.

Your purge-warning procedure is called for every handle that is about to be purged
(not necessarily for every purgeable handle in your heap, however). Your procedure should be able to determine quickly whether the handle it is passed is one whose associated data needs to be saved or otherwise processed.

SEE ALSO
See "Installing a Purge-Warning Procedure" on page 2-16 for a definition of a sample purge-warning procedure and for instructions on installing the procedure.


Previous Book Contents Book Index Next

© Apple Computer, Inc.
3 JUL 1996