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

  1. Path: sparky!uunet!wupost!gumby!yale!mintaka.lcs.mit.edu!ai-lab!life.ai.mit.edu!tmb
  2. From: tmb@arolla.idiap.ch (Thomas M. Breuel)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: Garbage Collection for C++
  5. Message-ID: <TMB.92Aug18123919@arolla.idiap.ch>
  6. Date: 18 Aug 92 16:39:19 GMT
  7. References: <1992Aug6.014619.2111@ucc.su.OZ.AU> <DAVEG.92Aug13025629@synaptx.synaptics.com>
  8.     <TMB.92Aug16164940@arolla.idiap.ch>
  9.     <1992Aug18.021453.24394@news.mentorg.com>
  10. Sender: news@ai.mit.edu
  11. Reply-To: tmb@idiap.ch
  12. Organization: IDIAP (Institut Dalle Molle d'Intelligence Artificielle
  13.     Perceptive)
  14. Lines: 86
  15. In-reply-to: bcannard@hppcb36.mentorg.com's message of 18 Aug 92 02:14:53 GMT
  16.  
  17. In article <1992Aug18.021453.24394@news.mentorg.com> bcannard@hppcb36.mentorg.com (Bob Cannard @ PCB x5565) writes:
  18.  
  19.    Simple as that. If there is a way of doing GC that is comparable to
  20.    the best manual - given all the other pain in C++ - I will accept
  21.    you argument, but it should prove hard to convince the larger C++
  22.    community.
  23.  
  24. I hope we can agree that GC costs you nothing if it doesn't run
  25. (malloc and free in the presence of GC don't look very different from
  26. the way they do now).
  27.  
  28. Now, if you dutifully manually free everything that you have
  29. allocated, then GC will never run, since you will never run out of
  30. memory. Hence, you don't incur any costs by having a GC sitting there.
  31.  
  32.    |> ... the same tricks you play in
  33.    |> C/C++ for memory management right now can also be applied in a GC'd
  34.    |> context so GC is at least not inherently slower than manual storage
  35.    |> management.
  36.  
  37.    How do you get the GC to figure out _at_compile_time_ that certain pieces
  38.    of memory become available at certain points in the program? That's the
  39.    big win for manual.
  40.  
  41. The GC doesn't have to figure it out. You do. GC (in particular,
  42. conservative GC) doesn't prevent you from doing manual storage
  43. management, it only permits you not to bother. Even in the presence
  44. of GC, you can continue to write your own "new" and "delete" functions
  45. (per class or global) that, for example, take storage from their own
  46. little storage pool, etc.
  47.  
  48.    |> Beyond these two facilities [providing a "free" function and
  49.    |> providing a separate allocation function for blocks of memory
  50.    |> that do not contain pointers], I simply fail to see the need to
  51.    |> divide memory or pointers "garbage collected" and "not garbage
  52.    |> collected" on the basis of efficiency.
  53.  
  54.    Because efficiency is a major issue, and the declaration could make a very
  55.    large difference.
  56.  
  57. I think you have failed to establish this claim.
  58.  
  59. Conservative GC with a "free" function is a safety net. If you don't
  60. run out of storage, you don't know it's even there. If you do run out
  61. of storage, it lets your program continue to run when it would
  62. otherwise have crashed. Whether you want to rely on this feature is up
  63. to you, but, in general, I can see no harm in having it in the
  64. language...
  65.  
  66. There are some minor semantic sticky points related to what to destroy
  67. when and pointer encoding. It would be nice to discuss those real
  68. issues once people have gotten over their odd hangups about the speed
  69. of GC.
  70.  
  71.                     Thomas.
  72.  
  73. PS: A technical point about suggested speedups from GC pointers
  74. vs non-GC pointers:
  75.  
  76.    |> OK, let's go through this again. You propose that there be "non-GC
  77.    |> pointers" in C++. I don't see how this helps speed.
  78.    |> 
  79.    |>  (1) The memory pointed to by non-GC pointers still needs to
  80.    |>      be examined by the garbage collector.
  81.  
  82.    No. The GC scans the various non-GC heaps to find (allocated) objects that
  83.    contain GC pointers. It does not have to determine whether or not those objects
  84.    are accessible; the fact that an object has been allocated but not deleted is
  85.    sufficient. Suppose such an object contains 6 pointers. In your conservative
  86.    scheme, those 6 pointers must then be checked because they might refer
  87.    to GC objects. If those pointers are declared non-GC, the GC doesn't even
  88.    have to think about them; it can go straight on to the next memory block.
  89.    Depending on the proportion of GC to non-GC, this could be a major saving.
  90.  
  91. If I read your paragraph correctly, you suggest that instead of
  92. carrying out the usual GC marking phase on both the GC heap and the
  93. non-GC heap, the non-GC heap is scanned once, linearly.
  94.  
  95. I don't think you are going to save any time over simply carrying out
  96. a normal mark phase for all objects. The reason is that during a
  97. normal mark phase, each block is scanned only once anyway, just as if
  98. you had done a linear scan of non-GC space.  Furthermore, your scheme
  99. requires the collector to distinguish between non-GC and GC pointers
  100. during collection; the cost of doing so is probably roughly equivalent
  101. to the cost of checking the "marked" bit on a block.
  102.  
  103.