This chapter gives you the information you need to get ZoneRanger installed and running. For new users, this chapter discusses some basic principles of memory management in the Mac OS environment, including heap zones, relocatable blocks, non-relocatable blocks, handles, pointers, and memory allocation.
This chapter includes the following topics:
If you can run CodeWarrior, you can run ZoneRanger. ZoneRanger requires a Motorola 68020 processor or better, or a PowerPC 601 or better processor. ZoneRanger needs approximately 1 MB of disk space and 640 KB of free RAM.
ZoneRanger requires System 7.1 or later (for 68K Mac OS systems) or System 7.1.2 or later (for PowerPC Mac OS systems), and Color QuickDraw.
ZoneRanger is a stand-alone application meant to help you analyze how your program is managing memory. ZoneRanger is not dependent on any part of the CodeWarrior IDE.
Installing ZoneRanger is simple. Choose one of two methods: automatic or manual.
The CodeWarrior Installer automatically installs ZoneRanger by choosing any of the following installations:
The Discover series has slightly different install options. You can install ZoneRanger by choosing any of the following installations:
Easy Install-absolutely everything for the CodeWarrior IDE ZoneRanger-from the Other Metrowerks Tools option in the Custom Install panel
To install ZoneRanger manually, locate the ZoneRanger folder on the installation CD. It is in the Other Metrowerks Tools folder. Copy the folder to your hard drive. There are no other files required.
A process is a running task of any type. A running application is a process. So is a desk accessory, the System, and other services that run in the background. Each process in the Mac OS has an associated heap zone.
The rest of this section discusses the following topics:
A heap zone is a range of contiguous addresses in the computer's memory dedicated to a process. In other words, it's a single chunk of RAM assigned to a process. The Process Manager creates the heap for a process when it launches the process. The size of the heap is based on the process's requested memory requirements (which you can see in an application's Get Info box in the Finder). If you are writing your own application, you can set the memory requirements in the PPC Project or 68K Project panel in the Project Settings dialog box.
NOTE Not all processes have to be applications. Some extensions also have a process associated with them. Extensions that display background screens are a good example. There is no way of changing the requested memory requirements of Extension processes. There are utilities that will let you see the memory requirements, however.
The heap zone is where a process works. For example, as an application does its work, it must create and dispose of blocks of memory for its own purposes. The application uses these blocks to store data. The Memory Manager allocates memory blocks in the heap zone on behalf of the process.
As with all rules there are exceptions, but in general everything a typical process does with memory happens inside its own heap zone.
There is no empty space in a heap zone. A heap zone consists of a zone header followed by a series of memory blocks. In turn, each individual block has a block header followed by the contents of the block. A block header contains the size, type, and attributes of the block.
The block size is the number of bytes in the block. A block has a physical size and a logical size. The physical size is the block header plus the size of the contents. There may also be a few unused "pad" bytes at the end of the block, because the Mac OS Memory Manager allocates space in even numbers of bytes. For example, if the block of memory you allocate is 15, the Memory Manager rounds the size to 16. The minimum number of bytes in a block is 12. The logical size is the size of the contents only.
There are three types of blocks. A block may be relocatable, non-relocatable, or free.
Relocatable blocks have attributes. There are three block attributes: locked, purgeable, and resource.
locked handle-cannot be moved around the heap zone. purgeable handle-can be converted to a free block if necessary. resource handle-contains the data from a resource.
A non-relocatable block never moves, so the address never changes. When you allocate a non-relocatable block, the Memory Manager gives you the address of the block-a pointer to the block.
When you allocate a relocatable block, the Memory Manager stores the address of the data in a special location called a master pointer. Every time the relocatable block moves, the Memory Manager updates the contents of the master pointer, so the master pointer always points to the right address for the data. When you allocate the relocatable block, the Memory Manager returns the address of the master pointer to you. This pointer to the master pointer is a handle. To find out where the data is, you look in the handle to get the master pointer, then look in the master pointer to find out where the data is at that moment.
The purpose behind relocatable blocks is simple. Because an application's memory demands vary from one moment to the next, it makes sense to be able to shuffle blocks of memory to make the most efficient use of available space. There are many times when the ability to move memory around prevents a program from crashing or being unable to function. If the Memory Manager didn't shuffle blocks of memory for you, you would have to do it yourself.
Inside Macintosh: Memory for more information on the structure of heap zones and memory blocks.