When viewing open source code (from OpenCV), I found the following code inside the method:
// copy class member to local variable for optimization int foo = _foo; //where _foo is a class member for (...) //a heavy loop that makes use of foo
From another question on SO I came to the conclusion that the answer to the question of whether to do this or not , or whether this is done automatically by the compiler, may be dependent on the compiler / installation.
My question is, will it matter if _foo was a member of the static class? Will there still be a problem in this manual optimization, or will access to a static member of a class be more "expensive" than to a local variable?
PS - I ask out of curiosity, and not to solve a specific problem.
Rotem source share