Flexible Memory Manager Routines
by Alan Wrigley

These routines can be added to your own programs, or included in WimpLib, (The RISC User library of Wimp routines), 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. For further details, see the Wimp Topics article in this month's RISC User magazine.

The routines can be added to WimpLib if required. An existing WimpLib function, FNwimperror, is called by one of the routines. 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 1994