![]() |
PurgeProcPtr |
||||
Header: | MacMemory.h | Carbon status: | Supported | |
User-defined function called when the Memory Manager needs to purge a block or allocate memory.
typedef void(* PurgeProcPtr) ( Handle blockToPurge );
You would declare your function like this if you were to name it MyPurgeCallback:
void MyPurgeCallback ( Handle blockToPurge );
A handle to the block that is about to be purged.
Whenever the Memory Manager needs to purge a block from the application heap, it first calls any application-defined purge-warning function that you have installed. The purge-warning function can, if necessary, save the contents of that block or otherwise respond to the warning.
Your purge-warning function is called during a memory-allocation request. As a result, you should not call any functions 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 function 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 function.
To install a purge-warning function, you need to assign its address to the purgeProc field of the associated zone header.
Note that if you call the Resource Manager function SetResPurge with the parameter TRUE, any existing purge-warning function is replaced by a purge-warning function installed by the Resource Manager. You can execute both warning functions by calling SetResPurge, saving the existing value of the purgeProc field of the zone header, and then reinstalling your purge-warning function. Your purge-warning function should call the Resource Managers purge-warning function internally.
Your purge-warning function 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 applications 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 function and the setting and restoring of the A5 register might have to be placed in separate functions.
The Memory Manager calls your purge-warning function for every handle that is about to be purged (not necessarily for every purgeable handle in your heap, however). Your function should be able to determine quickly whether the handle that the Memory Manager is about to purge points to data you need to save or otherwise process.
Supported in Carbon.