Inside one of my class methods I declare several local variables like this:
int findClosestPoint(double rRadius)
{
int iXIndexMult, iYIndexMult, iZIndexMult, iVoxelX, iVoxelY, iVoxelZ, iPIndexVoxel, iV, iV_From, iV_To;
double rDist, rDX, rDY, rDZ;
double rRadius2 = rRadius*rRadius;
double rMinDist = rRadius2;
int iFoundVertex = -1;
// do stuff
retrun iFoundVertex;
}
I'm calling this method thousands of times so I thought it would be a good idea to move variables declaration from method body to the class, so I recieved something like this:
int findClosestPoint(double rRadius)
{
rRadius2 = rRadius*rRadius;
rMinDist = rRadius2;
iFoundVertex = -1;
// do stuff
retrun iFoundVertex;
}
I was suprised because the result of this operation was significant performance drop in my program.
Can anyone may explain to me why that happened?