Originally Posted by
Daved
Can you post an example of what youare talking about?
This is a rather mundane instance but shows what I'm talking about.
Some variable names have been changed to protect the innocent!
This, to me, is much more clear...
Code:
float zeroOrderTerm = calInfo.getCoeff(mDir, CalibrationInfo::ZERO_ORDER_COEFF);
float firstOrderTerm = calInfo.getCoeff(mDir, CalibrationInfo::FIRST_ORDER_COEFF) * angleOfIncidence;
float secondOrderTerm = calInfo.getCoeff(mDir, CalibrationInfo::SECOND_ORDER_COEFF) * angleOfIncidence * angleOfIncidence;
float ref = zeroOrderTerm + firstOrderTerm + secondOrderTerm;
than this...
Code:
float ref = calInfo.getCoeff(mDir, CalibrationInfo::ZERO_ORDER_COEFF) +
(calInfo.getCoeff(mDir, CalibrationInfo::FIRST_ORDER_COEFF) * angleOfIncidence) +
(calInfo.getCoeff(mDir, CalibrationInfo::SECOND_ORDER_COEFF) * angleOfIncidence * angleOfIncidence);
Plus, in debugging, it allows you to view the intermediate values of the calculation step by step.
What I would really like to understand is what are the costs (overhead) of using stack variables. There's got to be some kind of document that someone has authored on the cost of pushing local variables on the stack vs. simply using a retrieved value directly.