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: Processes
Chapter 7 - Segment Manager / Using the Segment Manager


Loading Code Segments

The Segment Manager loads a code segment into memory automatically when you call any externally referenced routine in that segment. In most cases, the Segment Manager moves the block occupied by the code segment as high in the application heap as possible (by calling the Memory Manager procedure MoveHHi) and locks the block (by calling HLock) so that it cannot be moved or purged. You can disable or enable the call to MoveHHi and monitor the loading of segments into memory by manipulating two low-memory global variables.

If a code segment to be loaded is unlocked (that is, if it's not in memory and its resLocked attribute is clear, or if it is in memory and is unlocked), then the _LoadSeg trap calls the Memory Manager procedure MoveHHi to move the segment toward the top of the current heap. To prevent heap fragmentation, you should call the Memory Manager procedure MaxApplZone early in your application's execution. Otherwise, the heap will grow incrementally, and these automatic calls to MoveHHi may leave your code segments scattered throughout the heap. You can, however, disable the call to MoveHHi by setting the low-memory global variable SegHiEnable to 0. If this variable contains the value 0, _LoadSeg does not call MoveHHi to move the segment toward the top of the heap.

Occasionally, especially during application development, it is useful to monitor the otherwise largely invisible process of loading segments. You can do this by manipulating the system global variable LoadTrap. Before any routine in a newly loaded code segment is executed, the _LoadSeg trap inspects the LoadTrap global variable. If LoadTrap has a nonzero value, then _LoadSeg calls the _Debugger trap. This provides a useful way for you to monitor the loading of segments by the Segment Manager.


Previous Book Contents Book Index Next

© Apple Computer, Inc.
17 JUN 1996