Important: The information in this document is obsolete and should not be used for new development.
ReserveMem
Use theReserveMemprocedure when you allocate a relocatable block that you intend to lock for long periods of time. This helps prevent heap fragmentation because it reserves space for the block as close to the bottom of the heap as possible. Consistent use ofReserveMemfor this purpose ensures that all locked, relocatable blocks and nonrelocatable blocks are together at the bottom of the heap zone and thus do not prevent unlocked relocatable blocks from moving about the zone.
PROCEDURE ReserveMem (cbNeeded: Size);
cbNeeded- The number of bytes to reserve near the bottom of the heap.
DESCRIPTION
TheReserveMemprocedure attempts to create free space for a block ofcbNeededcontiguous logical bytes at the lowest possible position in the current heap zone. It pursues every available means of placing the block as close as possible to the bottom of the zone, including moving other relocatable blocks upward, expanding the zone (if possible), and purging blocks from it.Because
ReserveMemdoes not actually allocate the block, you must combine calls toReserveMemwith calls to theNewHandlefunction.Do not use the
ReserveMemprocedure for a relocatable block you intend to lock for only a short period of time. If you do so and then allocate a nonrelocatable block above it, the relocatable block becomes trapped under the nonrelocatable block when you unlock that relocatable block.
- Note
- It isn't necessary to call
ReserveMemto reserve space for a nonrelocatable block, because theNewPtrfunction calls it automatically. Also, you do not need to callReserveMemto reserve memory before you load a locked resource into memory, because the Resource Manager callsReserveMemautomatically.![]()
SPECIAL CONSIDERATIONS
Because theReserveMemprocedure could move and purge memory, you should not call it at interrupt time.ASSEMBLY-LANGUAGE INFORMATION
The registers on entry and exit forReserveMemare
Registers on entry D0 Number of bytes to reserve
Registers on exit D0 Result code RESULT CODES
noErr 0 No error memFullErr -108 Not enough memory