home *** CD-ROM | disk | FTP | other *** search
/ The Datafile PD-CD 3 / PDCD_3.iso / languages / panebasic / lib / blib2 / !BlibII / Docs / Memory < prev    next >
Encoding:
Text File  |  1993-01-25  |  2.6 KB  |  53 lines

  1.  
  2. Technical description of the Dynamic Memory Library
  3. ---------------------------------------------------
  4.  
  5.  
  6. This library supplies the 'Basic' user with dynamic memory allocation. The
  7. library allows convenient memory allocation, and more importantly
  8. deallocation, something lacking from Basic V.
  9.  
  10. This document contains information about the internal working of the
  11. library. You do not need to know how it works to use it.
  12.  
  13. When allocating memory the library will first scan it's free memory list for
  14. a block of the relevant size (or greater). If this fails it will claim extra
  15. memory from either Basic itself (via the DIM command) or from the WIMP (by
  16. expanding the wimpslot for the application). Where the library gets new
  17. memory from is defined by a global variable _mdim% (set via library
  18. procedures) which if TRUE makes it claim using the DIM command, and if FALSE
  19. memory is claimed from the free memory pool.
  20.  
  21. When memory is deallocated (using PROCfree) a scan of the free memory list
  22. is made so that the block being deallocated can be joined with any
  23. neighbouring free blocks. If it can't be joined to another block, it is
  24. simply added to the end of the free block chain (it is added to the head of
  25. the chain, thus the free chain is a LIFO stack). A check is also made to see
  26. if the wimpslot can safely be reduced because of the deallocation. 
  27.  
  28. The overhead of this allocation library is only one word (4 bytes) per
  29. allocated unit, plus upto 3 further bytes per unit due to the fact that
  30. memory is allocated in mulitples of 4 bytes. The extra word contains the
  31. length of the block and is used during deallocation and by the FNsize_of
  32. function. This extra word is located in the 4 bytes immediately preceeding
  33. the block.
  34.  
  35. The library performs no integrety checks what-so-ever, and thus any program
  36. which writes over the end of an allocated block may cause the library to
  37. crash or behave incorrectly (although this may not become apparent for some
  38. time). This library has been extensively tested and contains no known bugs
  39. or problems.
  40.  
  41. This library should be able to be compiled using RiscBASIC™, although
  42. problems may occure with ABC™.
  43.  
  44.  
  45. NOTE: This method of memory allocation will be much slower than using Risc-OS's
  46. own HEAP memory allocation routines. This method is used, basically, due to
  47. lack of documentation for the HEAP system available to the author at the
  48. current time. This library may be totally replaced at a later date.
  49.  
  50. If you really need a faster library for memory allocation, there is nothing
  51. stopping you replacing this library with one of your own (using the same
  52. procedure names will help though).
  53.