RISC User Heap Manager

by Alan Wrigley

This month's Wimp Topics article describes a useful amendment to the RISC User Heap Manager routines, which will greatly speed up the program when you are releasing a large block of memory. The disc contains two procedure libraries, StaticHeap and ShiftHeap which are used to implement a static heap memory manager and a shifting heap memory manager respectively. The original routines and their uses were fully described in the Wimp Topics articles in RISC User 7:5 and 9:1.

The routines can be added to your own programs to provide a memory manager which can be used to allocate blocks of memory for most storage purposes while the program is running. Example uses would be to store message files, user sprites, documents being edited, pointer lists and so on.

Before the routines can be used, your program needs to initialise three variables, appsize%, heap% and page% as follows:

     appsize%=HIMEM-&8000
     heap%=0
     SYS "OS_ReadMemMapInfo" TO page%

It is also assumed that your standard Wimp SWI call parameter block is called block%, and that the name of the application is held in appname$.

The full list of routines and their parameters is as follows:

FNallocate(size%)
Allocates a block of memory on request, size% bytes long. The function returns a pointer to the start of the block.

PROCdeallocate(ptr%)
Deallocates a block starting at ptr% previously allocated by FNallocate.

PROCalterblock(RETURN ptr%,size%)
Changes the size of a block starting at ptr% by size% bytes (positive to enlarge, negative to shrink).

PROCgetmemory
PROClosememory
PROCsetupheap

These procedures are only called by the routines described above and should not be called from elsewhere in the program.

 Copyright RISC User Magazine 1994,1995,1996
