RTTI Overhead in C++

前端 未结 4 2320
感情败类
感情败类 2020-12-15 05:46

What are the memory/performance overheads of enabling RTTI in a C++ program?
Can anyone please throw some light between the internal implementation of RTTI mechanism and

4条回答
  •  遥遥无期
    2020-12-15 05:55

    Please read appropriate section in this document.

    To sum up:

    • typeid (5.3.7): find vtable, through that find most derived class object, then extract type_info from that object's vtable. It is still very slow comparing with function call;

    • dynamic_cast (5.3.8): find type_info as described above, then determine whether conversion is possible, then adjust pointers. Run-time cost depends on the relative position in the class hierarchy of two classes involved. Down- and cross-casts are very slow these days (though here you can find the article about possible (but restricted) constant-time implementation of dynamic_cast).

提交回复
热议问题