Software, web, and programming tips: C++, Java, C, Linux, Windows, Cygwin, Firefox, Vim, WWW, RSS
Saturday, April 12, 2008
Friday, April 4, 2008
Virtual functions performance cost
From Efficient C++ Performance Programming Techniques:
Virtual functions seem to inflict a performance cost in several ways:
- The vptr must be initialized in the constructor.
- A virtual function is invoked via pointer indirection. We must fetch the pointer to the function table and then access the correct function offset.
- Inlining is a compile-time decision. The compiler cannot inline virtual functions whose resolution takes place at run-time.
Subscribe to:
Posts (Atom)