home *** CD-ROM | disk | FTP | other *** search
-
- Technical description of the Dynamic Memory Library
- ---------------------------------------------------
-
-
- This library supplies the 'Basic' user with dynamic memory allocation. The
- library allows convenient memory allocation, and more importantly
- deallocation, something lacking from Basic V.
-
- This document contains information about the internal working of the
- library. You do not need to know how it works to use it.
-
- When allocating memory the library will first scan it's free memory list for
- a block of the relevant size (or greater). If this fails it will claim extra
- memory from either Basic itself (via the DIM command) or from the WIMP (by
- expanding the wimpslot for the application). Where the library gets new
- memory from is defined by a global variable _mdim% (set via library
- procedures) which if TRUE makes it claim using the DIM command, and if FALSE
- memory is claimed from the free memory pool.
-
- When memory is deallocated (using PROCfree) a scan of the free memory list
- is made so that the block being deallocated can be joined with any
- neighbouring free blocks. If it can't be joined to another block, it is
- simply added to the end of the free block chain (it is added to the head of
- the chain, thus the free chain is a LIFO stack). A check is also made to see
- if the wimpslot can safely be reduced because of the deallocation.
-
- The overhead of this allocation library is only one word (4 bytes) per
- allocated unit, plus upto 3 further bytes per unit due to the fact that
- memory is allocated in mulitples of 4 bytes. The extra word contains the
- length of the block and is used during deallocation and by the FNsize_of
- function. This extra word is located in the 4 bytes immediately preceeding
- the block.
-
- The library performs no integrety checks what-so-ever, and thus any program
- which writes over the end of an allocated block may cause the library to
- crash or behave incorrectly (although this may not become apparent for some
- time). This library has been extensively tested and contains no known bugs
- or problems.
-
- This library should be able to be compiled using RiscBASIC™, although
- problems may occure with ABC™.
-
-
- NOTE: This method of memory allocation will be much slower than using Risc-OS's
- own HEAP memory allocation routines. This method is used, basically, due to
- lack of documentation for the HEAP system available to the author at the
- current time. This library may be totally replaced at a later date.
-
- If you really need a faster library for memory allocation, there is nothing
- stopping you replacing this library with one of your own (using the same
- procedure names will help though).
-