Call by reference

Problem Profiling shows that function calls are taking much of the real time.

Context During design, when establishing interfaces for functions (member functions and otherwise), or when improving the performance of an existing program.

Forces You want to treat objects like built-in data types, which means in part that you want to assume that they have efficient implementations. Yet efficiency in the C tradition comes from pointers, particularly in parameter lists, to defer the copying of data until it is actually used. An innocent-looking function call can trigger one or more constructor calls for each actual parameter. And those constructors may in turn allocate dynamic storage!

Most function parameters are actually const parameters in good object-oriented programs, whether the function prototypes capture that or not.

Except under the most arcane conditions, a function can assume that the lifetime of its actual parameters bounds the lifetime of the function's own activation record.

Solution Use call-by-reference instead of call-by-value. Make sure function prototypes capture the semantics of const where applicable.

Resulting
context
Constructors won't fire for function parameters, and the real-time overhead is reduced while maintaining equivalent functionality.

[Source: James Coplien, "After all, we can't ignore efficiency", C++ Report, May 96, p68]