home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!van-bc!rsoft!agate!ames!elroy.jpl.nasa.gov!decwrl!deccrl!bloom-beacon!eru.mt.luth.se!lunic!sunic!ericom!falcon!jonas
- From: jonas@beppe.ericsson.se (Jonas Nygren)
- Newsgroups: comp.lang.c++
- Subject: Re: destruction of temporaries
- Message-ID: <1992Aug19.113554.5464@ericsson.se>
- Date: 19 Aug 92 11:35:54 GMT
- References: <TMB.92Aug19113657@arolla.idiap.ch>
- Sender: news@ericsson.se
- Reply-To: jonas@beppe.ericsson.se
- Organization: Ericsson Telecom AB
- Lines: 55
- Nntp-Posting-Host: falcon.ericsson.se
-
- In article 92Aug19113657@arolla.idiap.ch, tmb@arolla.idiap.ch (Thomas M. Breuel) writes:
- > In article <1992Aug18.205211.16789@Warren.MENTORG.COM> adk@Warren.MENTORG.COM (Ajay Kamdar) writes:
- >
- > So why would the ARM consider the example with a temporary sufficient
- > reason to reject the "end of function" approach? To me it appears that
- > the "end of function" approach for temporaries would not cause any more
- > difficulties or program bugs than those that can already occur even without
- > temporaries. So why not reconsider that approach?
- >
- > I don't want my temporaries to hang around until the end of the
- > function. I often use large temporaries (megabytes), and I see no
- > reason why they should stick around any longer than I need them.
- >
- > Temporaries should get destroyed as soon as their value has been used.
-
- Yes used is the right word. I gave a small example in a previous posting where
-
- s2 = s1.sub(2,3);
-
- is OK, but
-
- s2 = s1.sub(2,3).strip();
-
- is not. Why should this use be disallowed??
-
- > To make call-by-reference a little more convenient, there is a special
- > rule for binding references to temporaries, and I guess that's OK.
-
- Why is this use OK, on what is your 'guessing' based??
-
- >
- > The properties of temporaries are no different (and no worse) than the
- > properties of automatic variables: pointers to them become invalid
- > when the object disappears.
-
- This is obvious. What we are discussing are when temporaries should disappear.
-
- >
- > If you want to be able to implement anything more powerful, you need
- > (surprise!) garbage collection (as stated in the ARM, p. 268). In the
-
- If you read the referenced pages closely there are many points of destruction
- which are discussed and each giving some more 'power'. The ultimate solution
- might be GC. But without GC in the language we could try to make the language
- more 'intuitive' by defining a reasonable behaviour for temporaries.
-
- > presence of GC, you would then actually have a choice of destroying
- > the temporary yourself (the current situation, safe if no pointers to
- > it have been handed out), or of not destroying it at the end of the
- > expression and letting the GC take care of it.
- >
- > Thomas.
-
-
- /jonas
-