AcornSearch - Acorn and RISC OS information searching
RISC OS Search
containing
"Nutty quip goes here!"
Home  |  About  |  Filebase Archive  |  StrongHelp Manuals  |  Newsgroups  |  Module Database
One of the biggest problems in programming multitasking programs (or single-
tasking ones for that matter) is memory management. For any program which has
more than one memory array which may change size during use it can get very
complicated. For this reason, WimpExtension provides a complete heap
manager. You call the initialise routine at the beginning of your program,
and from then on whenever you need some memory simply ask for it, and return
it when you don't need it any more. WimpExtension will automatically tidy the
heap, and reduce and enlarge the WimpSlot where necessary/possible.

The heap management system takes control of all your task's memory above the
start of the heap (specified when you call the initialise routine). You
should NOT change your task's WimpSlot when using the heap management routine
(ie. don't call Wimp_SlotSize with R0<>-1).

So that the memory blocks can be moved about by the tidy routine, you are not
given the address of the block, but the address of its 'anchor'. This is a
single word which points to the block. The tidy routine can then move the
block about and then update the anchor so you still know where it is. Note
that blocks will not mysteriously move on their own, they will only move on
calls to WimpExt_Heap, and then only for reason codes 5 and 6.

Note that the size of all memory blocks is a multiple of 8 plus 4 (ie.
size = 8N+4). The size will be rounded up on calls to the allocate routine.
The size of the block is stored 4 bytes before the start of the block. All
blocks are guaranteed word aligned.

The tidy routine can be automatically called once a second in WimpExt_PrePoll
if you set bit 3 of R2 when you call WimpExt_Initialise. Remember not to mask
out null events, though - it's probably best to use Wimp_PollIdle.

The routines are fairly robust, and will usually produce the error
'Heap corrupt' or 'Bad heap operation' rather than an address exception or
corrupting memory if something goes wrong. Both of these are really fatal
errors, but you can do with them what you like.

[sh-index] Back to list of manuals