4 ms·
Polymorphism doesn't have to add runtime overhead. You can achieve polymorphism without RTTI through code duplication, as C++ templates do. (You can also use un
by ootachi 15y ago
Polymorphism doesn't have to add runtime overhead. You can achieve polymorphism without RTTI through code duplication, as C++ templates do. (You can also use uniform value representations, like C void *, although this is limited in its applicability.)
- peterwoo 15y agoCode duplication is an overhead. Not as bad as RTTI, but static memory footprint is still important in the embedded/systems world -- sometimes more so than runtime memory footprint!
- barrkel 15y agoYou don't need any RTTI or code duplication for polymorphism, so long as you don't need general support for type-checked downcasts. If you do need type-checked downcasts, it can be as cheap as a single pointer on antirez's mylist->ops function table - a pointer pointing to the ancestor function table. (Specific support for any single downcast is trivial - just write a function for the function table, typed appropriately and implemented appropriately.)