Literally Everything You Need to Know About the Cost of Runtime Dispatch And How to Avoid It
When writing classic Object-Oriented Programming (OOP) in C++, we are taught to design our systems using polymorphism. We define a base class with virtual functions, inherit from it, and manipulate those objects using base class pointers. At runtime, the program dynamically selects the correct function execution based on the actual object type. This is known as dynamic (or runtime) dispatch. We will see below exactly what is happening behind the scenes. ...