Boost logo

Boost :

From: scleary_at_[hidden]
Date: 2002-06-28 15:29:00


There's a bunch going on, here. It's important to know what temporaries you
expect and what not. In each of your examples, RVO is in fact being used;
what you are trying to eliminate is the copy of your object created by the
function parameters (or explicitly created for your functions taking
reference parameters).

Most compilers will not do what you want -- and probably won't for quite a
while -- because the generated function must protect itself against improper
aliasing. Think again about what John Potter said about different
translation units. Read the examples in [12.2/2].

In order to reduce the number of copies below two for *any* of your examples
requires some *extremely* heavy optimization. And in that case, in theory
any of your implementations would be reduced to one copy (I think). BCC
won't do this, and from your post, it looks like GCC just started doing one
of them.

        -Steve

> -----Original Message-----
> From: Daniel Frey [mailto:daniel.frey_at_[hidden]]
> Sent: Friday, June 28, 2002 12:05 PM
> To: boost_at_[hidden]
> Subject: Re: [boost] operator implementation
>
>
> "Victor A. Wagner, Jr." wrote:
> >
> > "missed"? Unnamed return value optimization has been around longer.
> > Scott Meyers (I left his books at the office, so I can't
> quote which)
> > talked at length about why naming the temporary was likely
> to generate
> > WORSE code on most (at the time he wrote it) compilers.
>
> It's "More Efficient C++", Item 4.7. Please also read the errata,
> available at Scott's website. I haven't seen a single case where a
> compiler optimized away any of the unnamed return values for all the
> relevant tests (see csc++). I checked this for GCC 2.95.2, GCC 2.95.3,
> GCC 3.0.4, GCC 3.1, TenDRA 4.1.2, KAI CC (1 year ago, don't
> remember the
> version), Sun's CC and IIRC the HP-compiler (version: see KAI CC).
> Before the GCC 3.1, it made no difference for me as all
> compilers I know
> of didn't optimized the return value. With GCC 3.1, things changed and
> it was the first time I was able to remove the temporary with standard
> C++. The GCC 2.95.x had a special extension, which allowed something
> similar, but that was not portable. Still I'd like to hear about a
> single compiler that actually performs the RVO for Scott's example...
> (and from the thread in csc++, it isn't clear if it is allowed to be
> optimized :)
>
> Regards, Daniel
>
> --
> Daniel Frey
>
> aixigo AG - financial training, research and technology
> Schloß-Rahe-Straße 15, 52072 Aachen, Germany
> fon: +49 (0)241 936737-42, fax: +49 (0)241 936737-99
> eMail: daniel.frey_at_[hidden], web: http://www.aixigo.de
> _______________________________________________
> Unsubscribe & other changes:
> http://lists.boost.org/mailman/listinfo.cgi/boost
>


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk