home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c++
- Path: sparky!uunet!uunet.ca!frumious!pat
- From: pat@frumious.uucp (Patrick Smith)
- Subject: Re: Garbage Collection for C++
- Message-ID: <1992Aug29.054113.917@frumious.uucp>
- Date: Sat, 29 Aug 1992 05:41:13 GMT
- Reply-To: uunet.ca!frumious!pat
- References: <DAVEG.92Aug20022559@synaptx.synaptics.com> <1992Aug25.183619.9541@microsoft.com> <DAVEG.92Aug27002517@synaptx.synaptics.com>
- Organization: None
- Lines: 35
-
- daveg@synaptics.com (Dave Gillespie) writes:
- |Every third posting in the destruction-of-temporaries thread
- |in this group ends with "if only we had GC so we could solve this
- |problem once and for all..."
-
- Actually, I don't think adding GC to C++ would solve the problem
- of when to destroy temporaries.
-
- GC could help with cases such as this:
-
- String s, t;
- const char* p = (const char*) (s + t);
- // ... do something with p
-
- but I don't see how it would help with this:
-
- ofstream("some_file") << "Hello, " << "world!\n";
-
- Well, there is one way. One could require that all temporaries be
- allocated and destroyed by the garbage collection mechanism.
- There are at least two problems with this:
-
- 1) The destructors for the temporaries are run arbitrarily late,
- if indeed they are ever run (this depends on the rules GC is
- subject to). In the above example, the programmer probably
- wanted the ofstream destructor to be run fairly soon.
-
- 2) Some (most? almost all?) applications would run more slowly if
- temporaries were allocated from a garbage-collected heap instead
- of from the stack.
-
- --
- Patrick Smith
- uunet.ca!frumious!pat
- pat%frumious.uucp@uunet.ca
-