about the cost of virtual function

前端 未结 7 1772
没有蜡笔的小新
没有蜡笔的小新 2021-01-11 23:41

If I call a virtual function 1000 times in a loop, will I suffer from the vtable lookup overhead 1000 times or only once?

7条回答
  •  甜味超标
    2021-01-12 00:17

    I would say this depends on your compiler as well as on the look of the loop. Optimizing compilers can do a lot for you and if the VF-call is predictable the compiler can help you. Maybe you can find something about the optimizations your compiler does in your compiler documentation.

提交回复
热议问题