How to Allocate a Block of Heap Using NewPtr Toolbox Routine (45426)



The information in this article applies to:

  • Microsoft QuickBASIC Compiler for the Apple Macintosh 1.0

This article was previously published under Q45426

SUMMARY

The following applies to Microsoft QuickBASIC Version 1.00 for the Apple Macintosh.

The Toolbox routines for allocating and releasing heap space are contained in the Memory Manager. The NewPtr Toolbox function is used to allocate a block of memory from the heap and to return a pointer to that block. The pointer then can be used by your program to reference into that block of memory. When appropriate, the DisposPtr Toolbox function can be used to release the block the memory, as discussed in another article in this knowledgebase (query on DisposPtr and Toolbox).

MORE INFORMATION

The NewPtr Toolbox routine attempts to allocate a nonrelocatable block of memory from the current heap and if successful, return a pointer to the block. If the block cannot be allocated, NewPtr returns NUL.

The example below shows how to use the NewPtr Toolbox routine. It requires the use of one of the new ToolBox statements described in a separate article in this knowledgebase (query on "ToolBoxNewTOOL" or "ToolBoxNewOS").

Code Example

DIM regsarray&(5)
size& = 1024
Newptr& = &HA11E
ToolboxNewOS "I"
ToolboxNewOS "R",NewPtr&,regsarray&(0),,,(size&)

PRINT HEX$(regsarray&(0))      'print out the pointer
PRINT regsarray&(2)            'print out the error, 0 if none
				

Modification Type:MinorLast Reviewed:1/9/2003
Keywords:KB45426