Inlining
C++ offers an easy way to gain speed at the cost of space.
A sophisticated object-oriented program may make millions of function calls per second. Even if each function call takes a tiny amount of time, reducing the overhead from such calls can sometimes make the difference between acceptable and unacceptable performance.
If testing indicates that reducing function calls can help performance (and it is usually only a tiny minority of calls that are repeated often enough to be usefully optimized), then inlining lets you eliminate function call overhead at the price of increased program size.
There are two ways to inline. The simplest is to put the function implementation in the class declaration, as in this (non-template) version of ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access