Important: The information in this document is obsolete and should not be used for new development.
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
andHandle
define pointers and handles as follows:
TYPE SignedByte = -128..127; Byte = 0..255; Ptr = ^SignedByte; Handle = ^Ptr;TheSignedByte
type stands for an arbitrary byte in memory, just to givePtr
andHandle
something to point to. TheByte
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 typeProcPtr
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 makeaProcPtr
reference theMyProc
procedure by using the@
operator,
as follows:
aProcPtr := @MyProc;With the@
operator, you can assign procedures and functions to variables of typeProcPtr
, embed them in data structures, and pass them as arguments to other routines. Notice, however, that the data typeProcPtr
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 typeProcPtr
.
The Memory Manager uses the
- Note
- You can't use the
@
operator to reference procedures or functions whose declarations are nested within other routines.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 typeSize
. TheSize
data type is also defined as a long integer.
TYPE Size = LongInt;
© Apple Computer, Inc.
3 JUL 1996