Thanks all, my conclusions:
- making these variables mutable should work, but is tricky (as it is today akready), risk on faulty initializiation etc.
- since they're just simple ints and unsigned ints, no complex / higher level algorithms etc, I will create them all locally within the member functions and cleanup the ones in the class(es)
This also fits perfectly within the given principles.
Don't even look at it as if you have an option or choice there. Misusing a member variable for this purpose has many dire consequences:
- It inhibits some optimisation because at the very least, the final value must needlessly be written back into the member variable, and worst case may even cause the compiler to not use a register where it otherwise could.
- Stack allocation is cheap, very cheap. So cheap that adding an extra variable your stack frame normally has absolutely zero impact on performance.
- As a member it increases the amount of memory your class occupies. With many instances, and/or on smaller objects, this could bump up RAM usage very significantly.
- It simply will not work when you try to have nested functions using the same member variable as the for-loop variable.
- Making it mutable requires that you also wear the added runtime cost of making it threadsafe.
- Trying to use any functions which use the same member variable as a loop counter from multiple threads simply will not work.
Long story short, do not ever misuse use a member variable for the purpose of what should be a local loop variable.