Is there performance to be gained by moving storage allocation local to a member function to its cla
- by neuviemeporte
Suppose I have the following C++ class:
class Foo
{
double bar(double sth);
};
double Foo::bar(double sth)
{
double a,b,c,d,e,f
a = b = c = d = e = f = 0;
/* do stuff with a..f and sth */
}
The function bar() will be called millions of times in a loop. Obviously, each time it's called, the variables a..f have to be allocated. Will I gain any performance by making the variables a..f members of the Foo class and just initializing them at the function's point of entry? On the other hand, the values of a..f will be dereferenced through this-, so I'm wondering if it isn't actually a possible performance degradation. Is there any overhead to accessing a value through a pointer? Thanks!