Hi guys,
hope this is the right place to ask. I have a Class with an attribute that is used a lot. I could do this attribute public, but i want it readonly. So i did following:
MyController.h
class MyController
{
private:
// Timing
uint16_t nowTMinute;
public:
MyController();
uint16_t GetTMinute();
};
MyController.cpp
uint16_t MyController::GetTMinute() {
return nowTMinute;
}
Now for example i have following code each cylce:
Main.cpp
// Check for rise or dawn
if (Controller.GetTMinute() <= Config.Data.LowLights[ident].on_tmin + (Config.Data.LowLights[ident].rise_minutes)) {
// Rise
Controller.SetPWM(pwmPort, calcPwm((Controller.GetTMinute() - Config.Data.LowLights[ident].on_tmin), 1));
}
else if (Controller.GetTMinute() >= Config.Data.LowLights[ident].off_tmin - (Config.Data.LowLights[ident].dawn_minutes)) {
Controller.SetPWM(pwmPort, calcPwm((Config.Data.LowLights[ident].off_tmin - Controller.GetTMinute()), 0));
}
else { // MaxPower
Controller.SetPWM(pwmPort, (Config.Data.LowLights[ident].max_power));
}
Here i call the function a lot. Would be the performance much better if i did the Attribute public?
Or would it be better to declare a temp variable for the if statement like that:
uint8_t tmin = Controller.GetTMinute() ;
// Check for rise or dawn
if (tmin <= Config.Data.LowLights[ident].on_tmin + (Config.Data.LowLights[ident].rise_minutes)) {
// Rise
Controller.SetPWM(pwmPort, calcPwm((tmin - Config.Data.LowLights[ident].on_tmin), 1));
}
else if (tmin >= Config.Data.LowLights[ident].off_tmin - (Config.Data.LowLights[ident].dawn_minutes)) {
Controller.SetPWM(pwmPort, calcPwm((Config.Data.LowLights[ident].off_tmin - tmin ), 0));
}
else { // MaxPower
Controller.SetPWM(pwmPort, (Config.Data.LowLights[ident].max_power));
}
But then i declare an extra variable in the ram for "nothing" . Hope you can understand my question
Greetings,
Raphael