Dividing Memory Among Multiple Applications
In system 7.0 (or when running MultiFinder in system 5.0 and 6.0), the
user can have multiple applications open at once. The Operating System
organizes the available memory in a slightly different manner, as shown in the
figure below. Here two applications are open, sharing the available memory.
When multiple applications are open, there are multiple application
partitions, each with its own copy of QuickDraw global variables, application global variables, and so forth. Each application allocates and frees space within
its own application zone by using Memory Manager routines. Even though multiple applications are open, only one application at a time can have control
of the CPU. When your application is brought into the foreground or when it
receives processing time in the background, the Operating System ensures that
certain low-memory global variables have appropriate values and that the A5
register contains the address of the boundary between your application's
parameters and global variables.
It sometimes happens, however, that your routines execute at times when the
low-memory global variables and the A5 register are not set up for your
application. For instance, the application in partition 2 (in the figure below)
might have installed a Time Manager task to run periodically. That task can execute even though that application is not in control of the processor because
the Time Manager task executes at interrupt time. Problems may occur if that task tries to access any information in its
A5 world, for register A5 might not be pointing to its A5 world when the task
is called. Accessing this information includes reading or writing the values of
the application's global variables and QuickDraw global variables, as well as calling sub routines that are in different segments (because different segments
are accessed through the jump table, which is part of the A5 world).
In a task or completion routine that may run even when the application that
created it is not the active process, you need to save and restore the value of
the A5 register whenever you access information in the application's
A5 world. These tasks include all routines that execute at interrupt time,
routines, I/O completion routines, device drivers, and so forth. You can use the
discussion of these functions.
The memory organization in a multiple application environment