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: Memory /
Chapter 2 - Memory Manager / Memory Manager Reference
Memory Manager Routines / Allocating and Releasing Nonrelocatable Blocks of Memory


NewPtr

You can use the NewPtr function to allocate a nonrelocatable block of memory of a specified size.

FUNCTION NewPtr (logicalSize: Size): Ptr;
logicalSize
The requested size (in bytes) of the nonrelocatable block.
DESCRIPTION
The NewPtr function attempts to allocate, in the current heap zone, a nonrelocatable block with a logical size of logicalSize bytes and then return a pointer to the block. If the requested number of bytes cannot be allocated, NewPtr returns NIL.

The NewPtr function attempts to reserve space as low in the heap zone as possible for the new block. If it is able to reserve the requested amount of space, NewPtr allocates
the nonrelocatable block in the gap ReserveMem creates. Otherwise, NewPtr returns NIL and generates a memFullErr error.

SPECIAL CONSIDERATIONS
Because NewPtr allocates memory, you should not call it at interrupt time.

ASSEMBLY-LANGUAGE INFORMATION
The registers on entry and exit for NewPtr are
Registers on entry
A0Number of logical bytes requested
Registers on exit
A0Address of the new block or NIL
D0Result code

You can specify that the NewPtr function apply to the system heap zone instead of the current zone. To do so, set bit 10 of the routine trap word. In most development systems, you can do this by supplying the word SYS as the second argument to the routine macro, as follows:

_NewPtr ,SYS
If you want to clear the bytes of a block of memory to 0 when you allocate it with the NewPtr function, set bit 9 of the routine trap word. You can usually do this by supplying the word CLEAR as the second argument to the routine macro, as follows:

_NewPtr ,CLEAR
You can combine SYS and CLEAR in the same macro call, but SYS must come first.

_NewPtr ,SYS,CLEAR
RESULT CODES
noErr0No error
memFullErr-108Not enough memory

Previous Book Contents Book Index Next

© Apple Computer, Inc.
3 JUL 1996