lundi 23 février 2015

If vs boolean assignment speed C++

I have a function that is run ~60 times per second on a Nintendo DS (~50Hz CPU, ~3MB RAM). In this function I need to execute changed() only if the boolean has changed from false to true. Does the if statement increase the speed or decrease it?



bool variable = false; //Externally changed and accessed variable
bool oldVar; //Previous state of variable

void update()
{
//////////////////////////////////
if (!variable)
//////////////////////////////////
oldVar = variable;

if (variable && !oldVar)
{
oldVar = true;
changed();
}
}


Or is there a better way to do this entirely?


Aucun commentaire:

Enregistrer un commentaire