Reputation: 1232
Quick question: Do non virtual functions incur the cost of a vtbl lookup in classes with other virtual functions? For example:
Class A
{
virtual void init();
void update();
};
Class B : public A
{
void init();
}
A* = new B();
A->init();
while(true)
{
A->update();
}
Will the call to update incur the cost of a vtbl lookup? This code is very performance sensitive so I need to avoid virtual function calls. Thanks!
Upvotes: 3
Views: 127
Reputation: 6567
No. update() will not be in the vtable. Wikipedia had this to say: "Note that those functions not carrying the keyword virtual in their declaration ... do not generally appear in the vtable. There are exceptions for special cases as posed by the default constructor."
http://en.wikipedia.org/wiki/Virtual_method_table
Upvotes: 3
Reputation: 37364
If you don't call virtual functions inside your non-virtual functions, no vtbl lookup involved.
Upvotes: 1