Runtime Type Information (RTTI)

RTTI means performing dynamic type checking and type casting at runtime.
1. Increased Binary size with RTTI
When RTTI is enabled, the compiler includes additional metadata in the binary to support dynamic type information.
This metadata typically includes:
- type information tables (type descriptors)
- virtual function tables (vtables) used for dynamic dispatch etc
These tables increase the size of the binary, especially for programs with a large number of polymorphic classes.
2. Increased Execution time with RTTI
2.1 Dynamic Casts: Dynamic casts (dynamic_cast) involve runtime type checking to ensure the correctness of the cast. This type checking adds overhead to the execution time of the program.
2.2 Virtual Function Calls: Dynamic polymorphism in C++ works on virtual function calls, which require runtime lookup of the appropriate function. This lookup incurs additional runtime overhead compared to static dispatch


#include <iostream>
#include <typeinfo>

class Base {
public:
    virtual ~Base() {}
};

class Derived : public Base {};

int main() {
    Base* ptr = new Derived();
    Derived* derived = dynamic_cast <Derived*>(ptr);
    if (derived) {
        std::cout << "Dynamic cast successful\n";
    } else {
        std::cout << "Dynamic cast failed\n";
    }
    delete ptr;
    return 0;
}