Important: The information in this document is obsolete and should not be used for new development.
NewPtr
You can use theNewPtrfunction 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
TheNewPtrfunction attempts to allocate, in the current heap zone, a nonrelocatable block with a logical size oflogicalSizebytes and then return a pointer to the block. If the requested number of bytes cannot be allocated,NewPtrreturnsNIL.The
NewPtrfunction 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,NewPtrallocates
the nonrelocatable block in the gapReserveMemcreates. Otherwise,NewPtrreturnsNILand generates amemFullErrerror.SPECIAL CONSIDERATIONS
BecauseNewPtrallocates memory, you should not call it at interrupt time.ASSEMBLY-LANGUAGE INFORMATION
The registers on entry and exit forNewPtrare
Registers on entry A0 Number of logical bytes requested
Registers on exit A0 Address of the new block or NILD0 Result code You can specify that the
NewPtrfunction 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 wordSYSas 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 theNewPtrfunction, set bit 9 of the routine trap word. You can usually do this by supplying the wordCLEARas the second argument to the routine macro, as follows:
_NewPtr ,CLEARYou can combineSYSandCLEARin the same macro call, butSYSmust come first.
_NewPtr ,SYS,CLEARRESULT CODES
noErr 0 No error memFullErr -108 Not enough memory