Important: The information in this document is obsolete and should not be used for new development.
NewPtr
You can use theNewPtr
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
TheNewPtr
function attempts to allocate, in the current heap zone, a nonrelocatable block with a logical size oflogicalSize
bytes and then return a pointer to the block. If the requested number of bytes cannot be allocated,NewPtr
returnsNIL
.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 gapReserveMem
creates. Otherwise,NewPtr
returnsNIL
and generates amemFullErr
error.SPECIAL CONSIDERATIONS
BecauseNewPtr
allocates memory, you should not call it at interrupt time.ASSEMBLY-LANGUAGE INFORMATION
The registers on entry and exit forNewPtr
are
Registers on entry A0 Number of logical bytes requested
Registers on exit A0 Address of the new block or NIL
D0 Result 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 wordSYS
as the second argument to the routine macro, as follows:
_NewPtr ,SYSIf you want to clear the bytes of a block of memory to 0 when you allocate it with theNewPtr
function, set bit 9 of the routine trap word. You can usually do this by supplying the wordCLEAR
as the second argument to the routine macro, as follows:
_NewPtr ,CLEARYou can combineSYS
andCLEAR
in the same macro call, butSYS
must come first.
_NewPtr ,SYS,CLEARRESULT CODES
noErr 0 No error memFullErr -108 Not enough memory