home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #18 / NN_1992_18.iso / spool / comp / lang / cplus / 12487 < prev    next >
Encoding:
Internet Message Format  |  1992-08-17  |  4.5 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.92Aug17231725@synaptx.synaptics.com>
  6. Date: 18 Aug 92 06:17:25 GMT
  7. References: <1992Aug6.014619.2111@ucc.su.OZ.AU>
  8.     <TMB.92Aug14130323@arolla.idiap.ch>
  9.     <1992Aug16.075804.27511@mole-end.matawan.nj.us>
  10. Sender: daveg@synaptx.Synaptics.Com
  11. Organization: Synaptics, Inc., San Jose, CA
  12. Lines: 84
  13. In-reply-to: mat@mole-end.matawan.nj.us's message of 16 Aug 92 07:58:04 GMT
  14.  
  15. In article <1992Aug16.075804.27511@mole-end.matawan.nj.us> mat@mole-end.matawan.nj.us writes:
  16.  
  17. > The real problem with GC is that it is based on a particular model of
  18. > how a programming language represents something.  That model states
  19. > that the _value_ of something is all that matters; once the value
  20. > disappears, the identity means nothing.  On the other hand, C++, with
  21. > defined lifetimes for objects, declares that the object identity is
  22. > part of the model of computation.
  23.  
  24. Well, *can be* part of the model of computation.
  25.  
  26. > To put it differently, when does the destructor for a GC'd object get
  27. > called?
  28.  
  29. Answer number one:  When it's collected, of course!
  30.  
  31. Answer number two:  When you have GC, many of the reasons for using
  32. destructors go away.  There will always be classes that really need
  33. to do something active when they're destroyed, but the majority of
  34. the destructors I have seen do nothing more than delete temporary
  35. storage, adjust reference counts, and call other destructors, all
  36. of which can be made unnecessary with GC.
  37.  
  38. > What happens if the GC'd object's destructor makes a call that
  39. > has an effect outside the system?  In other words, what happens to
  40. > relationships between the objects in the system and the world outside?
  41.  
  42. If this matters, don't use GC for that object.  Delete it yourself.
  43. (I would certainly agree that "delete" needs to be retained in the
  44. language, no matter what kind GC is also provided.)
  45.  
  46. > A great deal of a program's information is stored in the relationships
  47. > between things, and not just in their values.  A GC'able language has
  48. > a certain semantic restriction: you will never use the actual object
  49. > (i.e. object-in-memory as C and C++ define the word) identity to represent
  50. > something.  If you have a reference to another object, it is because you
  51. > are interested in the value stored there, not in the object identity
  52. > itself.  Once the value is no longer accessible, the object identity is 
  53. > worthless.
  54.  
  55. I'm not sure I see where the "restriction" comes in.  We're not talking
  56. about taking anything out of C++; a GC proposal is not going to restrict
  57. anybody about how they use C++.  It will simply give them more options
  58. in how they manage their memory.
  59.  
  60. Suppose you have an existing C++ program.  Suppose there is an object
  61. in that program's memory that has been allocated and which no longer
  62. has any references to it of any sort, and which has not been deleted
  63. explicitly.  Most people would consider that a bug; a conscientious
  64. program ought to delete everything it allocates as a matter of
  65. principle; but your program is not planning on deleting the object
  66. because it no longer has any references to it.  Is there really so
  67. much harm in allowing the C++ runtime system to delete the object in
  68. that circumstance?  If you left the object dangling and it had a
  69. destructor that had a noticeable effect on the rest of the program,
  70. you almost certainly had a bug anyhow.
  71.  
  72. > C++ doesn't make this assumption.  Some data structures that are written
  73. > in C++ may, and GC may be suitable for those data structures.  But the
  74. > suitability of those data structures to GC shouldn't be mistaken for
  75. > the suitability of C++ for GC.
  76.  
  77. I've written plenty of programs that didn't use floats at all, so are
  78. floats not suitable for C++?
  79.  
  80. In fact, I've written programs that didn't use "new" at all.  I'm still
  81. glad to have it in the language, though, because I've written plenty
  82. of other programs that did.
  83.  
  84. Let's try a less pedantic example:  C++ breaks down around the edges
  85. on the issue of allocating arrays of class objects (it doesn't allow
  86. "operator new" to be overloaded on them, for example), but it still
  87. provides the feature because it's useful to many C++ programmers.
  88.  
  89. C++ is used for all sorts of programs, and all sorts of programming
  90. styles.  If there is any one overriding philosophy I see in C++, it's
  91. to give the programmer the tools to allow the best solution for the
  92. problem at hand.
  93.  
  94.                                 -- Dave
  95. --
  96. Dave Gillespie
  97.   daveg@synaptics.com, uunet!synaptx!daveg
  98.   or: daveg@csvax.cs.caltech.edu
  99.