Important: The information in this document is obsolete and should not be used for new development.
Summary of Memory Management
Pascal Summary
Data Types
TYPE SignedByte = -128..127; {arbitrary byte of memory} Byte = 0..255; {unsigned, arbitrary byte} Ptr = ^SignedByte; {pointer to nonrelocatable block} Handle = ^Ptr; {handle to relocatable block} ProcPtr = Ptr; {procedure pointer} Size = LongInt; {size, in bytes, of block}Memory Management Routines
Setting Up the Application Heap
PROCEDURE MaxApplZone; PROCEDURE MoreMasters; FUNCTION GetApplLimit : Ptr; PROCEDURE SetApplLimit (zoneLimit: Ptr);Allocating and Releasing Relocatable Blocks of Memory
FUNCTION NewHandle (logicalSize: Size): Handle; FUNCTION NewHandleClear (logicalSize: Size): Handle; PROCEDURE DisposeHandle (h: Handle);Allocating and Releasing Nonrelocatable Blocks of Memory
FUNCTION NewPtr (logicalSize: Size): Ptr; FUNCTION NewPtrClear (logicalSize: Size): Ptr; PROCEDURE DisposePtr (p: Ptr);Setting the Properties of Relocatable Blocks
FUNCTION HGetState (h: Handle): SignedByte; PROCEDURE HSetState (h: Handle; flags: SignedByte); PROCEDURE HLock (h: Handle); PROCEDURE HUnlock (h: Handle); PROCEDURE HPurge (h: Handle); PROCEDURE HNoPurge (h: Handle);Managing Relocatable Blocks
PROCEDURE EmptyHandle (h: Handle); PROCEDURE ReallocateHandle (h: Handle; logicalSize: Size); PROCEDURE ReserveMem (cbNeeded: Size); PROCEDURE MoveHHi (h: Handle); PROCEDURE HLockHi (h: Handle);Manipulating Blocks of Memory
PROCEDURE BlockMove (sourcePtr, destPtr: Ptr; byteCount: Size);Assessing Memory Conditions
PROCEDURE PurgeSpace (VAR total: LongInt; VAR contig: LongInt); FUNCTION MemError : OSErr;Grow-Zone Operations
PROCEDURE SetGrowZone (growZone: ProcPtr); FUNCTION GZSaveHnd : Handle;Setting and Restoring the A5 Register
FUNCTION SetCurrentA5 : LongInt; FUNCTION SetA5 (newA5: LongInt) : LongInt;Application-Defined Routines
Grow-Zone Functions
FUNCTION MyGrowZone (cbNeeded: Size): LongInt;C Summary
Data Types
typedef char SignedByte; /*arbitrary byte of memory*/ typedef unsigned char Byte; /*unsigned, arbitrary byte*/ typedef char *Ptr; /*pointer to nonrelocatable block*/ typedef Ptr *Handle; /*handle to relocatable block*/ typedef long (*ProcPtr)(); /*procedure pointer*/ typedef long Size; /*size in bytes of block*/Memory Management Routines
Setting Up the Application Heap
pascal void MaxApplZone (void); pascal void MoreMasters (void); #define GetApplLimit() (* (Ptr*) 0x0130) pascal void SetApplLimit (void *zoneLimit);Allocating and Releasing Relocatable Blocks of Memory
pascal Handle NewHandle (Size byteCount); pascal Handle NewHandleClear (Size byteCount); pascal void DisposeHandle (Handle h);Allocating and Releasing Nonrelocatable Blocks of Memory
pascal Ptr NewPtr (Size byteCount); pascal Ptr NewPtrClear (Size byteCount); pascal void DisposePtr (Ptr p);Setting the Properties of Relocatable Blocks
pascal char HGetState (Handle h); pascal void HSetState (Handle h, char flags); pascal void HLock (Handle h); pascal void HUnlock (Handle h); pascal void HPurge (Handle h); pascal void HNoPurge (Handle h);Managing Relocatable Blocks
pascal void EmptyHandle (Handle h); pascal void ReallocateHandle (Handle h, Size byteCount); pascal void ReserveMem (Size cbNeeded); pascal void MoveHHi (Handle h); pascal void HLockHi (Handle h);Manipulating Blocks of Memory
pascal void BlockMove (const void *srcPtr, void *destPtr, Size byteCount);Assessing Memory Conditions
pascal void PurgeSpace (long *total, long *contig); #define MemError() (* (OSErr*) 0x0220)Grow-Zone Operations
pascal void SetGrowZone (GrowZoneProcPtr growZone); #define GZSaveHnd() (* (Handle*) 0x0328)Setting and Restoring the A5 Register
long SetCurrentA5 (void); long SetA5 (long newA5);Application-Defined Routines
Grow-Zone Functions
pascal long MyGrowZone (Size cbNeeded);Assembly-Language Summary
Global Variables
ApplLimit long The application heap limit, beyond which the heap cannot expand. ApplZone long A pointer to the original application heap zone. BufPtr long Address of highest byte of allocatable memory. CurrentA5 long Address of the boundary between the application global variables and the application parameters of the current application. GZRootHnd long A handle to a block that the grow-zone function must not move. Result Codes
noErr 0 No error paramErr -50 Error in parameter list memROZErr -99 Heap zone is read-only memFullErr -108 Not enough memory nilHandleErr -109 NIL
master pointermemWZErr -111 Attempt to operate on a free block memPurErr -112 Attempt to purge a locked block memBCErr -115 Block check failed memLockedErr -117 Block is locked