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 1 - Introduction to Memory Management

This chapter is a general introduction to memory management on Macintosh computers. It describes how the Operating System organizes and manages the available memory, and it shows how you can use the services provided by the Memory Manager and other system software components to manage the memory in your application partition effectively.

You should read this chapter if your application or other software allocates memory dynamically during its execution. This chapter describes how to

You should be able to accomplish most of your application's memory allocation and management by following the instructions given in this chapter. If, however, your application needs to allocate memory outside its own partition (for instance, in the system heap), you need to read the chapter "Memory Manager" in this book. If your application has timing-critical requirements or installs procedures that execute at interrupt time, you need to read the chapter "Virtual Memory Manager" in this book. If your application's executable code is divided into multiple segments, you might also want to look at the chapter "Segment Manager" in Inside Macintosh: Processes for guidelines on how to divide your code into segments. If your application uses resources, you need to read the chapter "Resource Manager" in Inside Macintosh: More Macintosh Toolbox for information on managing memory allocated to resources.

This chapter begins with a description of how the Macintosh Operating System organizes the available physical random-access memory (RAM) in a Macintosh computer and how it allocates memory to open applications. Then this chapter describes in detail how the Memory Manager allocates blocks of memory in your application's heap and how to use the routines provided by the Memory Manager to perform the memory-management tasks listed above.

This chapter ends with descriptions of the routines used to perform these tasks. The "Memory Management Reference" and "Summary of Memory Management" sections
in this chapter are subsets of the corresponding sections in the remaining chapters in
this book.


Chapter Contents
About Memory
Organization of Memory by the Operating System
The System Heap
The System Global Variables
Organization of Memory in an Application Partition
The Application Stack
The Application Heap
The Application Global Variables and A5 World
Temporary Memory
Virtual Memory
Addressing Modes
Heap Management
Relocatable and Nonrelocatable Blocks
Properties of Relocatable Blocks
Locking and Unlocking Relocatable Blocks
Purging and Reallocating Relocatable Blocks
Memory Reservation
Heap Purging and Compaction
Heap Fragmentation
Deallocating Nonrelocatable Blocks
Reserving Memory
Locking Relocatable Blocks
Allocating Nonrelocatable Blocks
Summary of Preventing Fragmentation
Dangling Pointers
Compiler Dereferencing
Loading Code Segments
Callback Routines
Invalid Handles
Disposed Handles
Empty Handles
Fake Handles
Low-Memory Conditions
Memory Cushions
Memory Reserves
Grow-Zone Functions
Using Memory
Setting Up the Application Heap
Changing the Size of the Stack
Expanding the Heap
Allocating Master Pointer Blocks
Determining the Amount of Free Memory
Allocating Blocks of Memory
Maintaining a Memory Reserve
Defining a Grow-Zone Function
Memory Management Reference
Memory Management Routines
Setting Up the Application Heap
Allocating and Releasing Relocatable Blocks of Memory
Allocating and Releasing Nonrelocatable Blocks of Memory
Setting the Properties of Relocatable Blocks
Managing Relocatable Blocks
Manipulating Blocks of Memory
Assessing Memory Conditions
Grow-Zone Operations
Setting and Restoring the A5 Register
Application-Defined Routines
Grow-Zone Functions
Summary of Memory Management
Pascal Summary
Data Types
Memory Management Routines
Application-Defined Routines
C Summary
Data Types
Memory Management Routines
Application-Defined Routines
Assembly-Language Summary
Global Variables
Result Codes

Previous Book Contents Book Index Next

© Apple Computer, Inc.
3 JUL 1996