O'Reilly logo

Efficient C++ Performance Programming Techniques by David Mayhew, Dov Bulka

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Pass by Value

When passing an object by value, the initialization of the formal parameter with the actual parameter is equivalent to the following form [ES90]:

T formalArg = actualArg;

where T is the class type. Suppose g() is some function expecting a T argument when invoked:

void g (T formalArg)
{
    ...
}

A typical invocation of g() may look like:

T t;
g(t);

The activation record for g() has a place holder on the stack for its local argument formalArg. The compiler must copy the content of object t into g()'s formalArg on the stack. One popular technique of doing this will generate a temporary [Lip96I].

The compiler will create a temporary object of type T and copy-construct it using t as an input argument. This temporary will then be passed ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required