home *** CD-ROM | disk | FTP | other *** search
/ ftp.barnyard.co.uk / 2015.02.ftp.barnyard.co.uk.tar / ftp.barnyard.co.uk / cpm / walnut-creek-CDROM / CPM / MSOFT / MBASIC.FRE < prev    next >
Text File  |  2000-06-30  |  2KB  |  46 lines

  1. --------------------------------
  2.           MBASIC NOTES
  3. --------------------------------
  4.   A question asked quite frequently regarding MBASIC has to do 
  5. with "garbage collection"; or "Why does my MBASIC program 
  6. suddenly lock up in the middle of execution?".  
  7.   Many of our users are unfamiliar with the way MBASIC stores and 
  8. manipulates strings.  Perhaps the best way to explain how MBASIC 
  9. works with strings would be to use a short example program, and 
  10. show what the string space looks like after each instruction.
  11.  
  12. PROGRAM        STRING SPACE
  13. -------        ------------
  14. A$="TEST"      TEST
  15. B$="NEW"       TESTNEW
  16. A$="OLD"       TESTNEWOLD
  17. SWAP A$,B$     TESTNEWOLD
  18. A$=B$          TESTNEWOLDOLD
  19. PRINT FRE("")  OLD
  20.          VARIABLES
  21.          ---------
  22.          A$>TEST
  23.          A$>TEST B$>NEW
  24.          A$>OLD B$>NEW
  25.          A$>NEW B$>OLD
  26.          A$>OLD B$>OLD
  27.          A$>OLD B$>OLD
  28.  
  29.   As you can see, MBASIC stores each new string it comes upon by 
  30. APPENDING it to the end of the string space, NOT by overwriting 
  31. what is already there.  Notice that the unused strings are not 
  32. deleted until the FRE function is encountered.  The FRE function 
  33. forces MBASIC to reclaim the unassigned string space, by a 
  34. "garbage collection" process.  MBASIC will also perform this 
  35. garbage collection when string space is exhausted.
  36.   Thus, the larger the string space, the longer this process will 
  37. take.  This is why a large MBASIC program will sometimes "hang 
  38. up" for a few minutes when you least expect it.
  39.   There is no way to prevent this process from taking place; but 
  40. you CAN force it to take place when you want it to.  The FRE 
  41. function will return the number of bytes remaining in the string 
  42. space.  In order to do this, it must first force garbage 
  43. collection.  Given this, the line A=FRE("") may be used to force 
  44. garbage collection when YOU want it to happen.
  45.  
  46.