home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #18 / NN_1992_18.iso / spool / comp / lang / cplus / 12482 < prev    next >
Encoding:
Internet Message Format  |  1992-08-17  |  3.7 KB

  1. Path: sparky!uunet!synaptx!synaptics.com!daveg
  2. From: daveg@synaptics.com (Dave Gillespie)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: Garbage Collection for C++
  5. Message-ID: <DAVEG.92Aug17224359@synaptx.synaptics.com>
  6. Date: 18 Aug 92 05:43:59 GMT
  7. References: <1992Aug6.014619.2111@ucc.su.OZ.AU>
  8.     <DAVEG.92Aug13025629@synaptx.synaptics.com>
  9.     <TMB.92Aug16164940@arolla.idiap.ch>
  10.     <1992Aug18.021453.24394@news.mentorg.com>
  11. Sender: daveg@synaptx.Synaptics.Com
  12. Organization: Synaptics, Inc., San Jose, CA
  13. Lines: 71
  14. In-reply-to: bcannard@hppcb36.mentorg.com's message of 18 Aug 92 02:14:53 GMT
  15.  
  16. In article <1992Aug18.021453.24394@news.mentorg.com> bcannard@hppcb36.mentorg.com (Bob Cannard @ PCB x5565) writes:
  17.  
  18. >|>  (1) The memory pointed to by non-GC pointers still needs to
  19. >|>      be examined by the garbage collector.
  20.  
  21. > No. The GC scans the various non-GC heaps to find (allocated) objects that
  22. > contain GC pointers. It does not have to determine whether or not those objects
  23. > are accessible; the fact that an object has been allocated but not deleted is
  24. > sufficient.
  25.  
  26. Also:  The trickiest part of a conservative GC like KCL's is checking
  27. whether a given word really is a valid pointer.  While this can be done
  28. fairly efficiently, it's still not lightning-fast; KCL has to do a
  29. modulo operation each time, for example.
  30.  
  31. But the test for whether or not a pointer points *somewhere* in the
  32. GC-able zone of memory is trivial.  So if 90% of a program's allocation
  33. can use manual deletion, we can do that allocation in a different memory
  34. space and let the garbage collector do a trivial reject on 90% of
  35. the pointers (more or less).
  36.  
  37. >|>  (3) Even in a system with (conservative) GC, you can still return
  38. >|>      memory to the system using some form of unsafe "free" or "delete"
  39. >|>      (e.g., as provided by Boehm's collector).
  40.  
  41. > Agreed, but there has to be some point in doing so. I see two possible reasons
  42. > for having an explicit delete:
  43. > 1. To take advantage of any performance improvement. Regardless of who's
  44. >    right in this debate, I doubt that there is any benefit for GC objects.
  45. > 2. To invoke destructors at a specific point in time. This makes a lot more
  46. >    sense, even if the "delete" doesn't actually free the memory. This
  47. >    may prove important.
  48. > Any others?
  49.  
  50. The best one (IMHO):
  51.  
  52. Significant reduction in the number of GC's!  Again let's suppose 90%
  53. of our allocation can be deleted manually.  That means that, without
  54. doing any GC's, the amount of junk in memory grows only 10% as fast
  55. as with no deletion at all.  So, with GC's, it takes ten times as long
  56. to accumulate enough junk to cause another GC.
  57.  
  58. >|> [...] and (b) a
  59. >|> version of the "new" operator that says "this memory block doesn't
  60. >|> contain any pointers". Not surprisingly, these functions are offered
  61. >|> by conservative GC's for C/C++.
  62.  
  63. > Better to let the compiler make the choice. If GC pointers are declared, the
  64. > compiler can extend it to "this memory block doesn't contain any pointers
  65. > significant to the GC".
  66.  
  67. And even without that, the compiler can at least decide for a given
  68. "new" operation whether or not the data will contain *any* pointers.
  69.  
  70. >|> Now, it turns out that in some cases, GC is actually "guaranteed" to
  71. >|> be faster, in the sense that it can combine very low-cost allocation
  72. >|> with no overhead deallocation (that is, 0 machine cycles per word).
  73.  
  74. Well, now, this sounds like the same logic people use to ruin themselves
  75. with credit cards...  Remember, you still wind up paying (for deallocation),
  76. just later instead of right away.  But the convenience of paying later,
  77. and the efficiency of paying in chunks, is a big win.
  78.  
  79.                                 -- Dave
  80. --
  81. Dave Gillespie
  82.   daveg@synaptics.com, uunet!synaptx!daveg
  83.   or: daveg@csvax.cs.caltech.edu
  84.