A virtual method table is used in OOP languages, such as C++ and Java, to support polymorphism/virtual methods. Every instance of a polymorphic class has an associated virtual table, which is a list of pointers, pointing to each method. Calling methods of such classes then becomes a case of indexing that table and following the pointer. This way, instances of derived classes can have different pointers, allowing the correct method to be called for particular instances of child classes.

The creation of a virtual table considerably expands the size of a type, often quite expensive for a small class. It is usually suggested that destructors be made virtual if any methods in the class is virtual, as most of the overhead is in a header, and the cost per virtual function is quite small.

When using C++ however, it is possible to hack together even more deranged bugs than in C: with the use of pointers in C++ it is possible to overwrite virtual tables. Filling a virtual table with random bytes is a certain way to cause a crash.

Log in or register to write something here or to contact authors.