Enabling RTTI typically brings only a small overhead. The usual implementation carries a pointer to the type information structure in the vtable of an object. Since the vtable must be constructed anyway, the extra time is small - it's like adding another virtual function to the class.
typeid
is therefore comparable to calling a virtual function.
dynamic_cast
is slower - it needs to traverse the inheritance hierarchy to do a cast. Calling dynamic_cast
too frequently can be a performance bottleneck. By 'can' I mean that it usually won't …
There is a slight bloat in executable size since the typeinfo structures need to be stored somewhere. In most cases it won't be relevant.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…