Article View: comp.std.c++
Article #473Re: Unnecessary copying of returned object
From: Bjarne Stroustrup
Date: Sat, 01 Sep 1990 13:09
Date: Sat, 01 Sep 1990 13:09
19 lines
1024 bytes
1024 bytes
Antony Hodgson @ Massachusetts Institute of Technology writes
> Consider the following:
>
> Vector Vector::operator + ( Vector & A )
> {
> Vector temp;
> // for all valid i, temp[i] = (*this)[i] + A[i]
> return temp; // copy of temp made here
> } // temp deallocated here
>
> Could an intelligent compiler bypass this copying without the help of
> any new syntax?
Yes it could. The technique is described in the annotated C++ reference
manual in section 12.1.1c. I believe the technique is used in the Zortech
compiler (existence proof).
Technical Details
Message-ID:
<11266@alice.UUCP>Path:
arc1-ca.pugleaf.net!utzoo!utgpu!watserv1!watmath!att!dptg!ulysses!andante!alice!bsReferences:
<1990Aug31.234937.29938@athena.mit.edu> <1990Aug31.235606.166@athena.mit.edu>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!watserv1!watmath!att!dptg!ulysses!andante!alice!bs From: bs@alice.UUCP (Bjarne Stroustrup) Newsgroups: comp.std.c++ Subject: Re: Unnecessary copying of returned object Summary: can be avoided Message-ID: <11266@alice.UUCP> Date: 1 Sep 90 13:09:19 GMT References: <1990Aug31.234937.29938@athena.mit.edu> <1990Aug31.235606.166@athena.mit.edu> Organization: AT&T Bell Laboratories, Murray Hill NJ Lines: 19