I want to know why virtual function's footprint and performance is compared with normal function call.
Here is my analysis, please review whether I am correct. Thanks.
1. foorprint
Expand|Select|Wrap|Line Numbers
- class Foo
- {
- protected:
- char * pName;
- int nSize;
- virtual void copyName(char* pN) {return;}
- void virFunc() {return;}
- };
2. performance
2.1 Virtual function call's performance is worse than normal function call is because it needs to use __vfptr to find the virtual function table, then invokes the function. Here using __vfptr brings one more level of indirection compared with normal function call, which is the most important reason making the performance worse.
2.2 Are there anything else matters performance?
2.3 How to find normal function call address can be determined during compile time and virtual function call address can only be determined during runtime?
Please comment whether my understanding of 1 and 2 are correct or not?
thanks in advance,
George