Creating variables at runtime or not?

In which case local - inside a function is usually faster than global - outside any function.

Some other tips here - http://www.atmel.com/Images/doc8453.pdf

The reason that local variables are faster to work with is that global variables need to be read from memory and stored back into memory where as local variables only exist within the function so can be created in a register, used and then forgotten about once the function exits.

The effect is more noticable with bigger variables, a global long requires four reads (1 for each byte), four additions and four stores just to do this a++

A global unsigned char would bring this down to one read, one addition and one store

A local unsigned char could be as little as just one addition with no load or store instructions required - 12 times faster than the global long, three times fast than the global char.

Its never that simple in real life but thats the general idea.

Duane B

rcarduino.blogspot.com