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

  1. Newsgroups: comp.lang.c++
  2. Path: sparky!uunet!mcsun!sunic!ericom!falcon!jonas
  3. From: jonas@beppe.ericsson.se (Jonas Nygren)
  4. Subject: Re: Garbage Collection for C++
  5. Message-ID: <1992Aug14.101226.6929@ericsson.se>
  6. Sender: news@ericsson.se
  7. Nntp-Posting-Host: falcon.ericsson.se
  8. Reply-To: jonas@beppe.ericsson.se
  9. Organization: Ericsson Telecom AB
  10. References: <1992Aug13.153211.16572@ericsson.se>
  11. Date: Fri, 14 Aug 1992 10:12:26 GMT
  12. Lines: 100
  13.  
  14. I do not know if this really went out. So I am reposting my own article.
  15. /jonas
  16.  
  17. In article 16572@ericsson.se, jonas@beppe.ericsson.se (Jonas Nygren) writes:
  18. > In article 92Aug13025629@synaptx.synaptics.com, daveg@synaptics.com (Dave Gillespie) writes:
  19. > > > Any pointer to a GC class is a GC pointer, not an ordinary pointer.
  20. > > > GC objects declared on the stack or in other GC classes or static
  21. > > > are silently converted to GC references (GC pointers with
  22. > > > reference semantics).
  23. > > 
  24. > > I doubt this will be practical.  Partly because it would be too much
  25. > > of a nuisance to use C++ if you had to keep track of GC vs. non-GC
  26. > > pointers yourself, and partly because it would be impractical to
  27. > > convert the libraries (as many people have said).
  28. > > 
  29. > <gc discussion deleted>
  30. > I am experimenting with a reference counting scheme where the ref-counter is
  31. > placed in a class 'object', which every class that want to be shared must
  32. > inherit. To work with multipel inheritance class 'object' should be declared
  33. > public virtual. Class 'object' also has the information wether the object was
  34. > dynamically allocated or not. 
  35. > On destruction of class 'object' a check is performed that there are no references
  36. > to the object. If there are references we have dangling pointers and an assert/abort
  37. > will be executed which will terminate the program.
  38. > I use smart pointers based on templates to reference the instances which are 
  39. > derived from object. I call this smart-pointer class ref, in analogy with Simula.
  40. > A small example could look like:
  41. > class X : public virtual object { 
  42. >   public:
  43. >     int f();
  44. > };
  45. > ref<X> rx = new X;
  46. > rx->f();
  47. > rx = 0; // causes the allocated X to be deleted
  48. > ref's could also be used on auto/static allocated instances but these will never be 
  49. > deleted when there are no more outstanding references. 
  50. > I think this solution resembles the initial GC proposal for C++ very much,
  51. > that's why I wrote this. What do you think of this solution? What are the
  52. > drawbacks? The only drawback I have been able to identify is the general problem 
  53. > of circular references, which I see no solution for.
  54. > > Here are some more issues that you would have to worry about with
  55. > > a GC-ing C++:
  56. > > 
  57. > > What if a signal handler fires during a GC?  (Maybe you just have
  58. > > no choice but to have the system mask or disable signals during GC.)
  59. > I can't see any problem with my solution.
  60. > > 
  61. > > What if a GC occurs during a signal handler, and the interrupted
  62. > > program was in the middle of, say, constructing or destructing an
  63. > > object?  (I don't think you get bitten either way, but you'd want
  64. > > to check this *really carefully*!)
  65. > > 
  66. > > What if a pointer to a GC-able object is passed to foreign (non-C++)
  67. > > code, which stashes it somewhere the C++ collector doesn't know to
  68. > > look?  (All garbage-collecting languages have this problem, and as
  69. > > far as I know all they can do is shrug and warn programmers not to
  70. > > let go of the last C++ reference to an object if they know there
  71. > > might be non-C++ references still lurking around.)
  72. > You have to have libraries that support this mechanism. I am working on
  73. > an interpretation of NIHCL which uses my refs instead of pointers.
  74. > > 
  75. > > What if you have virtual base classes, and there are only references
  76. > > to the base part of an object?  The derived part of the object has
  77. > > a pointer to the base part but not the other way around, so the
  78. > > derived part might be collected in this case.  Can this ever be a
  79. > > problem?
  80. > > 
  81. > This is a circular reference situation my solution cannot handle.
  82. > > 
  83. > > Some food for thought,
  84. > >                                 -- Dave
  85. > > --
  86. > > Dave Gillespie
  87. > >   daveg@synaptics.com, uunet!synaptx!daveg
  88. > >   or: daveg@csvax.cs.caltech.edu
  89. > I would very much like to know what you think of my proposed solution.
  90. > /jonas
  91.  
  92.  
  93.  
  94.  
  95.