home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #18 / NN_1992_18.iso / spool / comp / lang / cplus / 12468 < prev    next >
Encoding:
Text File  |  1992-08-17  |  5.5 KB  |  128 lines

  1. Newsgroups: comp.lang.c++
  2. Path: sparky!uunet!news.mentorg.com!bcannard
  3. From: bcannard@hppcb36.mentorg.com (Bob Cannard @ PCB x5565)
  4. Subject: Re: Garbage Collection for C++
  5. Originator: bcannard@hppcb36
  6. Sender: news@news.mentorg.com (News User)
  7. Message-ID: <1992Aug18.021453.24394@news.mentorg.com>
  8. Date: Tue, 18 Aug 1992 02:14:53 GMT
  9. References: <1992Aug6.014619.2111@ucc.su.OZ.AU> <DAVEG.92Aug13025629@synaptx.synaptics.com> <TMB.92Aug16164940@arolla.idiap.ch>
  10. Nntp-Posting-Host: hppcb36.mentorg.com
  11. Organization: Mentor Graphics 
  12. Keywords: 
  13. Followup-To: 
  14. Lines: 112
  15.  
  16.  
  17. In article <TMB.92Aug16164940@arolla.idiap.ch>, tmb@arolla.idiap.ch (Thomas M. Breuel) writes:
  18. |> In article <1992Aug15.025613.4571@news.mentorg.com> bcannard@hppcb36.mentorg.com (Bob Cannard @ PCB x5565) writes:
  19. |> 
  20. |> OK, let's go through this again. You propose that there be "non-GC
  21. |> pointers" in C++. I don't see how this helps speed.
  22. |> 
  23. |>  (1) The memory pointed to by non-GC pointers still needs to
  24. |>      be examined by the garbage collector.
  25.  
  26. No. The GC scans the various non-GC heaps to find (allocated) objects that
  27. contain GC pointers. It does not have to determine whether or not those objects
  28. are accessible; the fact that an object has been allocated but not deleted is
  29. sufficient. Suppose such an object contains 6 pointers. In your conservative
  30. scheme, those 6 pointers must then be checked because they might refer
  31. to GC objects. If those pointers are declared non-GC, the GC doesn't even
  32. have to think about them; it can go straight on to the next memory block.
  33. Depending on the proportion of GC to non-GC, this could be a major saving.
  34.  
  35. This requires run-time type information at the start of each memory block. I
  36. can't see a way around that at the moment: this may prove a fatal flaw in the
  37. declared-GC scheme.
  38.  
  39. |>  (2) With a conservative GC, there is no tagging/untagging cost
  40. |>      associated with GC pointers; GC pointers are just as efficient
  41. |>      and simple as non-GC pointers.
  42.  
  43. Agreed.
  44.  
  45. |>  (3) Even in a system with (conservative) GC, you can still return
  46. |>      memory to the system using some form of unsafe "free" or "delete"
  47. |>      (e.g., as provided by Boehm's collector).
  48.  
  49. Agreed, but there has to be some point in doing so. I see two possible reasons
  50. for having an explicit delete:
  51.  
  52. 1. To take advantage of any performance improvement. Regardless of who's
  53.    right in this debate, I doubt that there is any benefit for GC objects.
  54.  
  55. 2. To invoke destructors at a specific point in time. This makes a lot more
  56.    sense, even if the "delete" doesn't actually free the memory. This
  57.    may prove important.
  58.  
  59. Any others?
  60.  
  61. |>  (4) Why ever would you _not_ want to call a GC if you run out
  62. |>      of "non-GC memory"? The alternative is a program crash.
  63. |> 
  64. |> It seems to me that the facilities you really want are: (a) an "free"
  65. |> function (which would be just as unsafe as it is now),
  66.  
  67. Hmm, not exactly. I can clearly and accurately specify the lifetimes of some
  68. of my data structures, whereas others are more open. Delete is used with a high
  69. degree of safety on the former; GC is needed for the latter.
  70.  
  71. |> and (b) a
  72. |> version of the "new" operator that says "this memory block doesn't
  73. |> contain any pointers". Not surprisingly, these functions are offered
  74. |> by conservative GC's for C/C++.
  75.  
  76. Better to let the compiler make the choice. If GC pointers are declared, the
  77. compiler can extend it to "this memory block doesn't contain any pointers
  78. significant to the GC".
  79.  
  80. |> Beyond these two facilities, I simply fail to see the need to divide
  81. |> memory or pointers "garbage collected" and "not garbage collected" on
  82. |> the basis of efficiency.
  83.  
  84. Because efficiency is a major issue, and the declaration could make a very
  85. large difference. Simple as that. If there is a way of
  86. doing GC that is comparable to the best manual - given all the other pain
  87. in C++ - I will accept you argument, but it should prove hard to convince
  88. the larger C++ community.
  89.  
  90. [snip]
  91. |> ... the same tricks you play in
  92. |> C/C++ for memory management right now can also be applied in a GC'd
  93. |> context so GC is at least not inherently slower than manual storage
  94. |> management.
  95.  
  96. How do you get the GC to figure out _at_compile_time_ that certain pieces
  97. of memory become available at certain points in the program? That's the
  98. big win for manual.
  99.  
  100. |> Now, it turns out that in some cases, GC is actually "guaranteed" to
  101. |> be faster, in the sense that it can combine very low-cost allocation
  102. |> with no overhead deallocation (that is, 0 machine cycles per word).
  103.  
  104. And in some cases manual allocation can do the same thing, if the programmer
  105. is prepared to take control of the memory allocation (some of my more critical
  106. data structures do exactly that). A GC system is still stuck with figuring out
  107. which memory areas are available for recycling - an overhead performed at
  108. compile time for manual.
  109.  
  110. The point remains: every optimisation that can be done for manual can also be
  111. done for GC, and vice-versa. _Except_ making a compile-time decision of when to
  112. delete memory. Maybe there are cases where a well-designed GC, fully integrated
  113. with the rest of the system, could do that, too. And I wouldn't be surprised
  114. to find that a simple conservative system works better than the current
  115. new and delete...
  116.  
  117. (I'm only arguing this point because it's important to whether or not
  118. GC pointers should be declared.)
  119.  
  120. Cheers,
  121.  
  122.       Bob.
  123.  
  124. -- 
  125. bob_cannard@mentorg.com         "Human beings? ... Well, I suppose they are a
  126.                                  form of life, even if they are unspeakable"
  127. Exprssed opinions are not necessarily those of Mentor Graphics Corporation.
  128.