ADC Home > Reference Library > Technical Notes > Legacy Documents > Carbon >
Legacy Document
Important: This document is part of the Legacy section of the ADC Reference Library. This information should not be used for new development.
Current information on this Reference Library topic can be found here:
|
IntroductionThe Memory Manager has been rewritten for Apple's PowerPC Macintosh computers. The new Memory Manager uses native PowerPC code and better algorithms for faster performance. It is also not as forgiving to ruthless programmers who break the rules defined in Inside Macintosh and Macintosh Technical Notes. First a conceptual clarification. The Memory Manager as documented in Inside Macintosh is a storage allocator. It organizes memory into "heaps" or "heap zones." Its architecture was not designed to support address space mapping, protection, or interrupt time allocation. The new Memory Manager uses the existing API that is documented in Inside Macintosh. If you code to the Macintosh API, you will inherit benefits of the new high-performance Memory Manager. Things Not to DoHere is a list of no-nos that may have appeared to work in the old Memory Manager, but may not with the new Memory Manager. Don't Dispose Blocks TwiceNever dispose of a memory block twice, and don't attempt to operate on a
disposed memory block. Although many traps return There are many subtle ways that a memory block can be disposed of twice.
Consider the following example. Joe Ruthless Programmer calls Stay Out of Free BlocksDo not modify data that exists in a free block, and don't attempt to read data or execute code out of a disposed memory block. Don't Use Fake Handles or Fake PointersCall Memory Manager routines only on memory blocks that were created by the
Memory Manager. Any call that operates on a pointer block must operate on a
pointer block created by the Memory Manager. Do not call Don't Make Calls at Interrupt TimeSince all calls either move memory or set low memory global variables (except
Don't Touch the Data StructuresDo not access or modify Memory Manager data structures directly. This includes
relocatable and nonrelocatable block headers, the heap header, and unused
master pointers. If there is an API available, use it. For example, there is an
API for locking and unlocking a handle. If you don't use it, you will break in
the future. Similarly, don't touch low memory global variables that are
maintained by the Memory Manager. Use Keep Your Caches CoherentBe careful with processors that have dual instruction and data caches, such as
the Motorola 68040. Since many clients manipulate code as data, the old Memory
Manager flushes caches frequently for compatibility. The new Memory Manager
flushes caches only when it moves blocks around. When in doubt, call
New Rules to Live ByThe new Memory Manager uses larger size block headers and a larger zone header. Clients must leave some slop space for future versions of the Memory Manager. When calculating how large to make a heap, use the following sizes: Overhead for heap header and trailer 256 bytes Overhead for each Memory Manager block 32 bytes Don't Assume Any Stack/Heap RelationshipsDon't assume that memory blocks cannot be above your stack. In the future, your
stack may be some other place than it is now. However, do call
Create Dynamic Heaps Inside Other Memory Manager Memory BlocksTo create subheaps, allocate a Memory Manager block and call Things It's Still OK to DoUse MoveHHiIt is recommended that you call Use Existing Tools to Your AdvantageMost popular debuggers for the Macintosh have a heap scramble feature. Use it to debug your code. This feature will ensure that subtle bugs are caught before shipping products to your customers. Similarly, use Zap Handles, Even Better Bus Error, and Double Trouble to ensure compatibility in the future. Although these utilities might not work with the new Memory Manager, you can test with them today using the old one. ConclusionWith the new high-performance Memory Manager, your applications will run faster. However, you need to follow the rules to be compatible in the future. ReferencesInside Macintosh: Memory Macintosh Technical Note: "OV 04 - Compatibility Why and How" Macintosh Technical Note: "OV 11 - The Joy of Being 32-Bit Clean" Macintosh Technical Note: "HW 06 - Cache as Cache Can" Downloadables
|