1200 dynamic_casts per second is not likely to be a major performance problem. Are you doing one dynamic_cast per image, or a whole sequence of if statements until you find the actual type?
If you’re worried about performance, the fastest ways to implement polymorphism are:
- — fastest —
- Function overloading (compile-time polymorphism only)
- CRTP (compile-time polymorphism only)
- Tags, switches and static casts (brittle, doesn’t support multi-level inheritance, a maintenance headache so not recommended for unstable code)
- Virtual functions
- Visitor pattern (inverted virtual function)
- — almost as fast —
In your situation, the visitor pattern is probably the best choice. It’s two virtual calls instead of one, but allows you to keep the algorithm implementation separate from the image data structure.