home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!crdgw1!uakari.primate.wisc.edu!aplcen.apl.jhu.edu!darwin.sura.net!wupost!gumby!yale!mintaka.lcs.mit.edu!ai-lab!life.ai.mit.edu!tmb
- From: tmb@arolla.idiap.ch (Thomas M. Breuel)
- Newsgroups: comp.lang.c++
- Subject: Re: destruction of temporaries
- Message-ID: <TMB.92Aug19113657@arolla.idiap.ch>
- Date: 19 Aug 92 15:36:57 GMT
- References: <1992Aug17.073500.24115@ericsson.se> <23466@alice.att.com>
- <1992Aug17.211508.6634@lucid.com>
- <1992Aug18.205211.16789@Warren.MENTORG.COM>
- Sender: news@ai.mit.edu
- Reply-To: tmb@idiap.ch
- Organization: IDIAP (Institut Dalle Molle d'Intelligence Artificielle
- Perceptive)
- Lines: 28
- In-reply-to: adk@Warren.MENTORG.COM's message of 18 Aug 92 20:52:11 GMT
-
- 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.
- 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.
-
- 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.
-
- 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
- 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.
-