home *** CD-ROM | disk | FTP | other *** search
/ Simtel MSDOS - Coast to Coast / simteldosarchivecoasttocoast2.iso / basic / garbage.col < prev    next >
Internet Message Format  |  1994-03-07  |  4KB

  1. Date: Wed, 17 Sep 86 16:06 CET
  2. From: Wolfgang Strobl <STROBL%DBNGMD21.BITNET at ucbvax.Berkeley.EDU>
  3. To:   Info-IBMPC at MIT-MC
  4. Re:   Slow Garbage-Collector in BASICA
  5.  
  6. In Issue 84 KAPLAN@RED.RUTGERS.EDU reports a problem with BASIC's
  7. garbage collector and asks for help:
  8.  
  9. > I would like to be able to program around this somehow. I have tried
  10. > to avoid using temporary storage for string variables; I name each
  11. > intermediate string result. (Am I making a mistake to do this?) I
  12. Yes.
  13. > thought this would keep the interpreter from proliferating lots of
  14. > intermediate strings and thereby use up storage.
  15.  
  16. No. It's the other way round: with IBM'S/Microsoft's BASICA
  17. temporaries don't produce garbage, string assignments do.
  18. In order to demonstrate this, run the following short program:
  19.  +------------------------------------------------------+
  20.  I 10 PRINT"Part 1: temporaries don't produce garbage:" I
  21.  I 20 A$="Hallo":N=0:M=0:FS=0:B$="":FS=FRE(0)           I
  22.  I 30 IF MID$(A$,2,3)="all" THEN N=N+1                  I
  23.  I 40 PRINT ,N,FS-FRE(0)                                I
  24.  I 50 IF N<3 THEN 30                                    I
  25.  I 60 PRINT"Part 2: string assignments do:"             I
  26.  I 70 B$=MID$(A$,2,3):IF B$="all" THEN M=M+1            I
  27.  I 80 PRINT ,M,FS-FRE(0)                                I
  28.  I 90 IF M<3 THEN 70                                    I
  29.  I 100 PRINT"Part 3: enforced garbage collection:"      I
  30.  I 110 M=FRE(""):PRINT ,"back to",FS-FRE(0)             I
  31.  +------------------------------------------------------+
  32. This gives the following output:
  33.  +---------------------------------------------+
  34.  I  Part 1: temporaries don't produce garbage: I
  35.  I                 1             0             I
  36.  I                 2             0             I
  37.  I                 3             0             I
  38.  I  Part 2: string assignments do:             I
  39.  I                 1             3             I
  40.  I                 2             6             I
  41.  I                 3             9             I
  42.  I  Part 3: enforced garbage collection:       I
  43.  I                back to        3             I
  44.  +---------------------------------------------+
  45.  
  46. In a response to the question Mike Scheutzow wrote:
  47.  
  48. > There is one other thing you should know: Each time fre(0) [or
  49. > whatever command is used to get the amount of unused memory] is
  50. > called, the interpreter *must* do GC in order to be able to reliably
  51. > report the amount of free space.  When you noticed that memory "reset
  52. > to 50K", it was because your program no longer was using it, not
  53. > because GC was performed.
  54. >
  55. > Whatever is happening during that 10 to 15 minutes, it ain't GC.
  56.  
  57. This is wrong, as You may deduce from the output of the above sample
  58. program. According to my BASICA manual, a call to FRE with a string type
  59. parameter (FRE("") or FRE(A$)) enforces an early garbage collection.
  60. FRE(0) (or FRE(A)) reports the amount of storage, which is not used and
  61. not garbage, without doing any garbage collection.  They suggest to call
  62. FRE("") periodically in Your Program, in order to get more, but shorter
  63. garbage collection delays.
  64.  
  65. Mike Scheutzows comment may result from experience with an earlier
  66. Microsoft BASIC. Microsoft has changed BASIC's storage handling a couple
  67. of times since its first version of BASIC (remember those 8K-
  68. ROM-Basic's?)
  69.  
  70. Summary: place DUMMY=FS("") at a frequently visited position in Your
  71. program. You may try IF INITIAL.FS-FRE(0)<5000 THEN INITIAL.FS=FRE("")
  72. too.
  73.  
  74. Wolfgang Strobl, STROBL@DBNGMD21.BITNET
  75.