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

Inlining Virtual Methods

We previously noted that some compilers will refuse to inline virtual methods. This may have seemed like it should be obvious. After all, a virtual method is one for which the binding is delayed until run-time. Virtual methods are generally considered to be always called indirectly via a function pointer table. Although this view of virtual methods is in general accurate, it is not totally so. Take, for example, the following code fragment:

inline
virtual
int x::y (char* a)
{
    ...
}

void z (char* b)
{
    x_base* x_pointer = new x(some_arguments_maybe);
    x x_instance(maybe_some_more_arguments);
    x_pointer->y(b);
    x_instance.y(b);
}

y() is a virtual method, but its binding doesn't always need to be delayed until runtime. In ...

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