home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #19 / NN_1992_19.iso / spool / comp / lang / cplus / 13040 < prev    next >
Encoding:
Text File  |  1992-08-29  |  1.6 KB  |  47 lines

  1. Newsgroups: comp.lang.c++
  2. Path: sparky!uunet!uunet.ca!frumious!pat
  3. From: pat@frumious.uucp (Patrick Smith)
  4. Subject: Re: Garbage Collection for C++
  5. Message-ID: <1992Aug29.054113.917@frumious.uucp>
  6. Date: Sat, 29 Aug 1992 05:41:13 GMT
  7. Reply-To: uunet.ca!frumious!pat
  8. References: <DAVEG.92Aug20022559@synaptx.synaptics.com> <1992Aug25.183619.9541@microsoft.com> <DAVEG.92Aug27002517@synaptx.synaptics.com>
  9. Organization: None
  10. Lines: 35
  11.  
  12. daveg@synaptics.com (Dave Gillespie) writes:
  13. |Every third posting in the destruction-of-temporaries thread
  14. |in this group ends with "if only we had GC so we could solve this
  15. |problem once and for all..."
  16.  
  17. Actually, I don't think adding GC to C++ would solve the problem
  18. of when to destroy temporaries.
  19.  
  20. GC could help with cases such as this:
  21.  
  22.    String s, t;
  23.    const char* p = (const char*) (s + t);
  24.    // ... do something with p
  25.  
  26. but I don't see how it would help with this:
  27.  
  28.    ofstream("some_file") << "Hello, " << "world!\n";
  29.  
  30. Well, there is one way.  One could require that all temporaries be
  31. allocated and destroyed by the garbage collection mechanism.
  32. There are at least two problems with this:
  33.  
  34. 1) The destructors for the temporaries are run arbitrarily late,
  35.    if indeed they are ever run (this depends on the rules GC is
  36.    subject to).  In the above example, the programmer probably
  37.    wanted the ofstream destructor to be run fairly soon.
  38.  
  39. 2) Some (most? almost all?) applications would run more slowly if
  40.    temporaries were allocated from a garbage-collected heap instead
  41.    of from the stack.
  42.  
  43. -- 
  44. Patrick Smith
  45. uunet.ca!frumious!pat
  46. pat%frumious.uucp@uunet.ca
  47.