Determining Features of Temporary Memory
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);
Boolean TempMemCallsAvailable()
{
OSErr myErr; // result code returned by Gestalt
long myRsp; // response returned by Gestalt
// prototype for error handling routine
void DoError(OSErr);
// Checking for availability of trap
Boolean TrapAvailable( short trapNum);
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
}
else // Gestalt is not available
return TrapAvailable(_OSDispatch);
return FALSE;
}
The TrapAvailable function is defined in Determining Whether a Trap
Is Available.under About Compatibility. You can use similar code to
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).