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.190009.411@frumious.uucp>
- Date: Sat, 29 Aug 1992 19:00:09 GMT
- Reply-To: uunet.ca!frumious!pat
- References: <DAVEG.92Aug27002517@synaptx.synaptics.com> <1992Aug29.054113.917@frumious.uucp> <TMB.92Aug29174821@arolla.idiap.ch>
- Organization: None
- Lines: 50
-
- tmb@idiap.ch writes:
- |In article <1992Aug29.054113.917@frumious.uucp> pat@frumious.uucp (Patrick Smith) writes:
- | 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
- |
- |If GC were added to the C++ language, this would still not work.
- |You would need to write something like:
- |
- | String s,t;
- | const char *p = (const char *)new String(s+t);
-
- What I had in mind was that one would write the String class so that
- the actual character array was stored in garbage collected memory.
- The String destructor would not release this memory; that would be
- left for the garbage collection mechanism to do. In that case, I
- would expect the code I gave to work correctly.
-
- Note that I did not say that GC would solve the problem itself; I just
- said that it would help with the solution.
-
-
- |If you wanted to do something like this frequently, you might be able
- |to define a class HeapString that eliminates the need for an explicit
- |call to "new".
-
- By this do you mean something along the lines of my suggestion above?
-
-
- | but I don't see how it would help with this:
- |
- | ofstream("some_file") << "Hello, " << "world!\n";
- |
- |This code is wrong, and it would continue to be wrong in the presence
- |of GC.
-
- It's wrong because of the current rules for destruction of temporaries.
- Changing those rules _might_ make this work as the programmer
- expected. Just adding GC would not. That was my point.
- I take it you agree.
-
- --
- Patrick Smith
- uunet.ca!frumious!pat
- pat%frumious.uucp@uunet.ca
-