[ACCEPTED]-How expensive are dynamic casts in C++?-dynamic-cast
Accepted answer
1200 dynamic_cast
s per second is not likely to be a 9 major performance problem. Are you doing 8 one dynamic_cast
per image, or a whole sequence of if
statements 7 until you find the actual type?
If you're 6 worried about performance, the fastest ways 5 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 4 visitor pattern is probably the best choice. It's 3 two virtual calls instead of one, but allows 2 you to keep the algorithm implementation 1 separate from the image data structure.
Source:
stackoverflow.com
More Related questions
Cookie Warning
We use cookies to improve the performance of the site. By staying on our site, you agree to the terms of use of cookies.