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


Data Types

This section discusses the general-purpose data types defined by the Memory Manager. Most of these types are used throughout the system software.

The Memory Manager uses pointers and handles to reference nonrelocatable and relocatable blocks, respectively. The data types Ptr and Handle define pointers and handles as follows:

TYPE
   SignedByte     = -128..127;
   Byte           = 0..255;
   Ptr            = ^SignedByte;
   Handle         = ^Ptr;
The SignedByte type stands for an arbitrary byte in memory, just to give Ptr and Handle something to point to. The Byte type is an alternative definition that treats byte-length data as an unsigned rather than a signed quantity.

Many other data types also use the concept of pointers and handles. For example, the Macintosh system software stores strings in arrays of up to 255 characters, with the first byte of the array storing the length of the string. Some Toolbox routines allow you to pass such a string directly; others require that you pass a pointer or handle to a string. The following type definitions define character strings:

TYPE
   Str255         = STRING[255];
   StringPtr      = ^Str255;
   StringHandle   = ^StringPtr;
Some Toolbox routines allow you to execute code after a certain amount of time elapses or after a certain condition is met. Any such routine requires you to pass the address of the routine containing the code to be executed so that it knows what routine to call when the time has elapsed or the condition has been met. You use the data type ProcPtr to define a pointer to a procedure or function.

TYPE ProcPtr = Ptr;
For example, after the declarations

VAR
   aProcPtr: ProcPtr;

PROCEDURE MyProc;
BEGIN
            ...
END;
you can make aProcPtr reference the MyProc procedure by using the @ operator,
as follows:

aProcPtr := @MyProc;
With the @ operator, you can assign procedures and functions to variables of type ProcPtr, embed them in data structures, and pass them as arguments to other routines. Notice, however, that the data type ProcPtr technically points to an arbitrary byte, not an actual routine. As a result, there's no direct way in Pascal to access the underlying routine via this pointer in order to call it. (See Listing 2-4 on page 2-13 for some assembly-language code you can use to do so.) The routines in the Operating System and Toolbox, which are written in assembly language, can however, call routines designated by pointers of type ProcPtr.

Note
You can't use the @ operator to reference procedures or functions whose declarations are nested within other routines.
The Memory Manager uses the Size data type to refer to the size, in bytes, of memory blocks. For example, when specifying how large a relocatable block you want to allocate, you pass a parameter of type Size. The Size data type is also defined as a long integer.

TYPE Size      = LongInt;

Previous Book Contents Book Index Next

© Apple Computer, Inc.
3 JUL 1996