vendredi 6 février 2015

Place variables frequently used by the same function on the heap?


Say that I have the following situation:



void myFunc()
{
int x;
//Do something with x
}


"x" is placed on the stack which is no doubt fast.


Now, "myFunc" is called very frequently, lets say 10 times per second. Is it plausible to do something like this:



int x;
void myFunc()
{
//Do something with x
}


so that x gets allocated in the applications data segment. but it is allocated only once. Since "myFunc" is called so frequently, does the second approach deliver any performance benefits?





Aucun commentaire:

Enregistrer un commentaire