RE: Returning by reference faster than returning by reference

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi Nava,

Your subject isn't quite right.  It should be "Returning by reference faster than returning by value".

C++ has RVO ("return value optimization").

RVO is part of C++, just as the elide constructors is a part of C++.

Also note:  you get RVO even if you are -O0.  It really is part of the C++ language, even for non-optimized compiling.

So your two tests as given should have the about the same performance, since the two tests are basically doing the same thing.  And, indeed, they do have about the same performance.  As expected.

Read carefully the constraints upon when RVO can be applied.  (I don't have a URL handy.  You'll have to use your Google-fu, or read the ISO 14882 standard.)

In situations where RVO cannot be applied, then for non-trivial data types, an output reference parameter will (likely) be faster.

A lot of STL and Boost rely upon RVO for their template magic to be highly performant.

HTH,
--Eljay


[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux