With assist in the question Fast and flexible iterator for abstract class I produced an abstract GridIterator to have an abstract class GridData. Now I can use any concrete subclass of GridIterator to iterate through any concrete subclass of GridData.
However, throughout testing I discovered the virtual operator++ and virtual operator* operators become real bottlenecks of my calculations. I'm wondering if there's anything I'm able to do in order to speed up. Due to the abstraction, inlining most likely will not work with me?
Let me give a const Iterator too. I don't know how to make this happen using the current class design. Mentioning to my original question ( Fast and flexible iterator for abstract class ), can one just produce a ConstGridIterator as subclass from the STL forward iterator with const T rather than T? Or must i implement a const version of each and every single iterator class (the GridIterator and baseImpl)?
Do because the STL and do not use virtual techniques within an iterator or containers. Most compilers, when requested to optimize, can optimize out most STL iterators to the stage they're completely side stepped plus they don't even appear in the item file. For instance a
*(vector<T>.begin()+5) might be enhanced to
vector<T>.__underlying_array even when
vector<T>::iterator is really a complex class with constructors, destructors and sophisticated operator redefinitions.
Getting an online method call any place in the phone call stack of
operator !=() avoid the compiler to optimize this properly since the method might be changed by anything. virtual techniques don't have only a little runtime overhead, they create the code unoptimizable by which makes it more modular.
If you would like performance, think about using templates rather than inheritance, or tweak your compiler, stating that nobody inherit these kinds. This might conflict together with your current design, but you have to choose two focal points among individuals three : performance, modularity and price.