So What Techncial Notes

Call Box
Allocating Your Own Memory

Written by: William Stephens - January 15,1990
Revised by: William Stephens - February 15,1990

This technical note describes how to use CALL LC (Long Call) to allocate memory blocks for your own use in the higher banks of the Apple IIgs memory range.

Some programs need data buffers for special data needed by a particular programming applications. These buffers (blocks) can be allocated by using a Long Call to the Memory Managers New Handle function. This function needs a user I.D. to allocate blocks with and this I.D. is present in the Call Box Global Page. Use the following statement to get the user I.D. number:

ID = 6144 + PEEK(PO + 180)

This statement creates a special user I.D. in the form of $18xx, where xx is the assigned user I.D. for the Call Box Basic Driver. Once you have a user I.D. you can then allocate a block of memory.

CALL LC,_0,_$1000,ID,$0000,_0\$0902\_H
IF H = 0 THEN (memory allocation error handler)

This statement will allocate the block of memory and return a HANDLE for the block allocated. This handle is important to remember for de-allocating the block later on so keep this variable H however needs to be DEFERENCED (De-Referenced) to derive a pointer to the memory block which is what you need to address the block of memory from your application. Use the following statement to deference the handle:


Now H will contain the handle of the memory block and P will contain its pointer.

The techniques outlined here apply to many toolbox functions which can be accessed by CALL LC. Some routines will require a user I.D. and some will require handles or pointers ... by using these statements you will be able to derive the right kind of data for your tool calls.

Further Reference
Call Box BASIC Manual V2.0
Apple IIgs Toolbox Reference: Volume(s) 1,2 and 3

Apple is a registered trademark of Apple Computer Inc.

Call Box - So What Software 10221 Slater Ave. Suite 103 Fountain Valley, CA. 92708