IT lexicon › Programming › Vtable (virtual method table)

Vtable (virtual method table)

Programming På svenska → Updated: 2026-11-05

The table of function pointers that routes a virtual method call to the right subclass, at the cost of one indirect jump per call.

Every class with virtual methods gets a table, and every object carries a hidden pointer to it — the vptr — usually at the very start. A call like shape->area() becomes three steps: load the vptr, load the pointer at the right index, jump. The cost is small but real, and above all the indirect jump blocks inlining. Hence the effort compilers pour into devirtualization.

The exact layout is an ABI matter. The Itanium C++ ABI, written for Intel's IA-64 around 1999, became the de facto standard once GCC 3.0 adopted it on every platform in 2001 — breaking binary compatibility with 2.95 in the process. MSVC has its own layout. Rust does it differently: the vtable pointer travels in a fat pointer next to the data rather than inside the object.

← Back to the lexicon