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

  1. Path: sparky!uunet!ogicse!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.92Aug16164940@arolla.idiap.ch>
  6. Date: 16 Aug 92 20:49:40 GMT
  7. Article-I.D.: arolla.TMB.92Aug16164940
  8. References: <1992Aug6.014619.2111@ucc.su.OZ.AU> <DAVEG.92Aug13025629@synaptx.synaptics.com>
  9.     <TMB.92Aug14130323@arolla.idiap.ch>
  10.     <1992Aug15.025613.4571@news.mentorg.com>
  11. Sender: news@ai.mit.edu
  12. Reply-To: tmb@idiap.ch
  13. Organization: IDIAP (Institut Dalle Molle d'Intelligence Artificielle
  14.     Perceptive)
  15. Lines: 95
  16. In-reply-to: bcannard@hppcb36.mentorg.com's message of 15 Aug 92 02:56:13 GMT
  17.  
  18. In article <1992Aug15.025613.4571@news.mentorg.com> bcannard@hppcb36.mentorg.com (Bob Cannard @ PCB x5565) writes:
  19.  
  20.    In a *fair* comparison between an optimised GC and an optimised
  21.    manual scheme, the manual scheme will win if the decision of when and what to
  22.    delete can be made at compile time. In a situation where the decision can only
  23.    be made at run time, the GC will win. This is one reason why I want both
  24.    mechanisms.
  25.  
  26. OK, let's go through this again. You propose that there be "non-GC
  27. pointers" in C++. I don't see how this helps speed.
  28.  
  29.  (1) The memory pointed to by non-GC pointers still needs to
  30.      be examined by the garbage collector.
  31.  
  32.  (2) With a conservative GC, there is no tagging/untagging cost
  33.      associated with GC pointers; GC pointers are just as efficient
  34.      and simple as non-GC pointers.
  35.  
  36.  (3) Even in a system with (conservative) GC, you can still return
  37.      memory to the system using some form of unsafe "free" or "delete"
  38.      (e.g., as provided by Boehm's collector).
  39.  
  40.  (4) Why ever would you _not_ want to call a GC if you run out
  41.      of "non-GC memory"? The alternative is a program crash.
  42.  
  43. It seems to me that the facilities you really want are: (a) an "free"
  44. function (which would be just as unsafe as it is now), and (b) a
  45. version of the "new" operator that says "this memory block doesn't
  46. contain any pointers". Not surprisingly, these functions are offered
  47. by conservative GC's for C/C++.
  48.  
  49. Beyond these two facilities, I simply fail to see the need to divide
  50. memory or pointers "garbage collected" and "not garbage collected" on
  51. the basis of efficiency.
  52.  
  53. The only need to distinguish the two kinds of pointers would arise (as
  54. it does in Modula-3) if you additionally introduce Lisp-like runtime
  55. type and range information in an effort to make your language safer.
  56. Frankly, much as I prefer such systems, I can't see this happening in
  57. C++, and the issues involved go far beyond GC.
  58.  
  59. Altogether, I think there is very little that actually needs to be
  60. done to the C++ language to support conservative GC, beyond adding few
  61. more standardized hooks.
  62.  
  63. The real issues, as I seem them, are not to divide non-GC from GC
  64. pointers, but to deal with questions of finalization. One particularly
  65. important question to me is whether the existing "delete" in a GC
  66. implementation should by default not deallocate memory (just call the
  67. destructor), or whether it should correspond to the "unsafe delete"
  68. mentioned above.
  69.  
  70. Implementors, of course, have a little more work cut out for them,
  71. like slight modifications to over-eager optimizers.
  72.  
  73.                     Thomas.
  74.  
  75. PS:
  76.  
  77.    |> What "hits"? In all the cases that I have looked at, the GC overhead
  78.    |> has been _smaller_ than the overhead of explicit memory management in
  79.    |> C++. Now, maybe my sample of programs is biased, but if you claim that
  80.    |> there are "hits", please state either whether you have concrete
  81.    |> evidence that there are, or whether your statement is just religious
  82.    |> belief. Your vague statements might easily turn into gospel truth.
  83.    |> 
  84.    |> Based on my experience, I would turn your statement around and say:
  85.    |> "those of us who want GC shouldn't have to suffer the inefficiencies
  86.    |> of not having it".
  87.  
  88.    It's practical experience. A question for you: have you ever used a
  89.    custom-made, tailored new/delete (or malloc/free), instead of the ones provided
  90.    as standard?
  91.  
  92. I have written custom-made, tailored new/delete, not just for C++, but
  93. also for languages with GC. Yes, indeed, practically all the tricks
  94. you play with memory management in C/C++ also work in fully garbage
  95. collected environments.
  96.  
  97. PPS:
  98.  
  99.    There are plenty of reasons whey GC is genuinely more efficient
  100.    than manual: it allows better-designed data structures, it
  101.    eliminates the need to copy data which plagues large systems using
  102.    manual recycling, and it reduces development and maintenance costs.
  103.    But the idea that GC is inherently faster than manual is bogus.
  104.  
  105. As I stated above (believe it or not), the same tricks you play in
  106. C/C++ for memory management right now can also be applied in a GC'd
  107. context, so GC is at least not inherently slower than manual storage
  108. management.
  109.  
  110. Now, it turns out that in some cases, GC is actually "guaranteed" to
  111. be faster, in the sense that it can combine very low-cost allocation
  112. with no overhead deallocation (that is, 0 machine cycles per word).
  113.