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

Lazy Evaluation

Paying a performance penalty for a computation you ultimately may not need is a bad idea. It happens way too often in complex code. You should not perform costly computations “just in case.” Costly computations should be performed only if necessary. That often means deferring computations until they are actually needed, hence the name Lazy Evaluation [Mey96, ES90].

Back in the days of pure C programming we were in the habit of defining all of our variables up front, at the beginning of each routine. In C++, object definitions trigger constructors and destructors and that may be expensive. It leads to eager evaluation—something we want to avoid. The Lazy Evaluation principle suggests that we ought to delay object definition to ...

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