Determining Features of Temporary Memory
Because the temporary memory routines are present only on systems that are
running MultiFinder (or on systems in which the functionality of MultiFinder
is a standard part of the Operating System) and because the features of those
routines have changed in system 7.0, you should always check that those
routines are available and that they have the features you require before
calling them. This is easy to do if the Gestalt function is available because Gestalt includes a selector to determine whether those routines are present in the operating environment and, if they are, whether the temporary memory
handles are real (that is, whether you can use the normal Memory Manager routines to manipulate them) and whether those handles are tracked. It is also
possible to determine whether the routines are available even if the Gestalt function is not available.
You can determine whether the temporary memory routines are implemented
by checking the return value of the TempMemCallsAvailable function that
is defined in the code example below.
// Determining whether temporary memory routines are available
// Assuming inclusion of MacHeaders
#include <Gestaltequ.h>
#define _OSDispatch 0xA88F // trap number of temp memory routines
Boolean gHasGestalt; // global variable set if system has Gestalt or not // Prototype your routine like this prior to using it
Boolean TempMemCallsAvailable(void); {
OSErr myErr; // result code returned by Gestalt long myRsp; // response returned by Gestalt
// prototype for error handling routine
// Checking for availability of trap
if ( gHasGestalt ) { // gHasGestalt is set by other code
myErr = Gestalt( gestaltOSAttr, &myRsp);
if ( myErr )
DoError(myErr);
else
return myRsp & 0x0008; // test bit 4, which represents
// tempmem support
}
return FALSE;
}
determine whether temporary memory handles are real and whether the
temporary memory is tracked (that is, you can hold temporary memory until
your application terminates).