Carbon


Memory Manager

Carbon supports the majority of the Memory Manager programming interface. Changes primarily affect applications that use zones, system memory, or temporary memory. For example, temporary memory allocations in Mac OS X are allocated in the application’s address space. As a result, calling TempNewHandle is effectively the same as calling NewHandle.

Carbon does not support current functions for accessing the system heap, but on OS X, you can use the POSIX shared memory APIs to achieve this functionality. In addition, the virtual memory system in Mac OS X introduces a number of changes in the addressing model.

By adhering to the following guidelines, you can increase your application’s compliance with Mac OS X memory management:

• Try to use memory only within your own application heap. Review the places where you allocate memory in the system heap.

• Do not pass pointers to data among applications through Apple events, Gestalt routines, or other means. For example, don’t share Toolbox data structures between applications, because in Mac OS X, each application will run in its own protected address space.

• Do not use inline, hard-coded addresses.

• Do not modify the zone header by calling the MoreMasters function. You should instead call the function MoreMasterPointers. Note, however, that master pointer blocks do not need to be preallocated or optimized in the Mac OS X environment, so MoreMasterPointers will only benefit Carbon applications running on Mac OS 8.

• Don’t make assumptions about the layout of memory, such as the relative position of data stored in heaps, stacks, and other memory areas.

• Don’t use the DisposePtr or DisposeHandle functions on pointers or handles allocated by Toolbox managers. For example, don’t call the function DisposeHandle on a control allocated by the NewControl function; use DisposeControl instead.

• Because Mac OS X applications run in a large, protected memory space, memory sizing routines such as MaxMem and FreeMem work differently than before.


© 2000 Apple Computer, Inc. (Last Updated 6/30/2000)