More Effective C ++ 24

xiaoxiao2021-04-01  215

Terms 24: Understanding the cost of Virtual Functions, Multiple Inheritance, Virtual Bases, Runtime Type Identification

VTBL is Virtual Tables, VPTRS is Virtual Table Pointers. This has a detailed description in "Inside C Object Model", so don't write more here. "Inside C Object Model" has a related performance test report, which can be used as a reference. When we declare the virtual function into inline, don't have fantasies, the compiler tends to ignore, because if this setting takes effect, if all virtual functions are inline, how to generate vtbl? And inline is a compile period, Virtual is a performance period. So don't be inline, don't be Virtual.

Multiple inheritance is actually not a good abstract way, I have the most hateful characteristics. It is recommended not to use it unless the quarter falls. This can also avoid Virtual Base Classes at the same time. Runtime Type Identification is not a common feature, which is relatively, which is ignored, as long as VC6 is not supported by default.

Summary, Virtual Functions, Multiple Inheritance, Virtual Base Classes, Runtime Type Identification is required, and my point of view is unless necessary, it is not necessary.

转载请注明原文地址:https://www.9cbs.com/read-131066.html

New Post(0)