home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #18 / NN_1992_18.iso / spool / comp / lang / cplus / 12621 < prev    next >
Encoding:
Internet Message Format  |  1992-08-19  |  3.8 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.92Aug20023846@synaptx.synaptics.com>
  6. Date: 20 Aug 92 09:38:46 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.     <TMB.92Aug18123919@arolla.idiap.ch>
  12. Sender: daveg@synaptx.Synaptics.Com
  13. Organization: Synaptics, Inc., San Jose, CA
  14. Lines: 67
  15. In-reply-to: tmb@arolla.idiap.ch's message of 18 Aug 92 16:39:19 GMT
  16.  
  17. In article <TMB.92Aug18123919@arolla.idiap.ch> tmb@arolla.idiap.ch (Thomas M. Breuel) writes:
  18.  
  19. > I hope we can agree that GC costs you nothing if it doesn't run
  20. > (malloc and free in the presence of GC don't look very different from
  21. > the way they do now).
  22.  
  23. Well, as long as you don't introduce tagged pointers, maintain a
  24. linked list of all GC pointers, or anything like that.  (And I think
  25. most of us would agree that you'd want to avoid all those things if
  26. you possibly can, and it looks like you can pretty easily.)
  27.  
  28. > Conservative GC with a "free" function is a safety net. If you don't
  29. > run out of storage, you don't know it's even there. If you do run out
  30. > of storage, it lets your program continue to run when it would
  31. > otherwise have crashed.
  32.  
  33. In particular, it's a very useful safety net:  If the GC has a mode
  34. when it reports how many bytes were collected, it can aid debugging
  35. of a program that is supposed to be 100% careful about deleting
  36. things manually.  If the GC finds anything to collect, then you
  37. must have dropped somethings somewhere.
  38.  
  39. Combined with a manual way to invoke the GC on demand, this is a
  40. tool on a par with the malloc_verify operations some libraries
  41. provide.
  42.  
  43. >    [...]  Suppose such an object contains 6 pointers. In your conservative
  44. >    scheme, those 6 pointers must then be checked because they might refer
  45. >    to GC objects. If those pointers are declared non-GC, the GC doesn't even
  46. >    have to think about them; it can go straight on to the next memory block.
  47. >    Depending on the proportion of GC to non-GC, this could be a major saving.
  48.  
  49. > If I read your paragraph correctly, you suggest that instead of
  50. > carrying out the usual GC marking phase on both the GC heap and the
  51. > non-GC heap, the non-GC heap is scanned once, linearly.
  52.  
  53. To make this practical, you'd need three heap classes:  Objects that
  54. the GC can collect; non-collectable objects that still may contain
  55. pointers to collectable objects (this would be the safest default
  56. type of allocation); and non-collectable objects that are known not
  57. to contain pointers to collectable objects.
  58.  
  59. If you have a "non-GC" declaration, the compiler can automatically
  60. decide when a given "new" can use this third heap area.  Even without
  61. that, it can certainly use the third area for any type that contains
  62. no pointers at all (say, big arrays of ints or doubles).
  63.  
  64. The GC doesn't have to scan the third area at all.  Suppose you have
  65. an image-processing program that allocates various data structures,
  66. along with some huge one-megabyte arrays of numbers.  The three-area
  67. approach allows the GC to completely ignore these numeric arrays.
  68.  
  69. > Furthermore, your scheme
  70. > requires the collector to distinguish between non-GC and GC pointers
  71. > during collection; the cost of doing so is probably roughly equivalent
  72. > to the cost of checking the "marked" bit on a block.
  73.  
  74. That's probably true, but with three-area allocation, classes which
  75. contain *only* non-GC pointers can be optimized at compile-time.  In
  76. practice most systems would probably ignore the non-GC declaration
  77. except for the case where all the pointers are declared non-GC.
  78.  
  79.                                 -- Dave
  80. --
  81. Dave Gillespie
  82.   daveg@synaptics.com, uunet!synaptx!daveg
  83.   or: daveg@csvax.cs.caltech.edu
  84.