Quote:Original post by Kwak
I thought "int i;" means that new memory must be allocated for a new (temporary) variable and memory allocation takes time?
Its not memory allocation, its a simple pointer operation. The stack pointer gets moved by sizef(int) bytes. With static, the variable exists for the duration of your program, so is always present, but doesnt need that operation every time the function is called.
With the CPU time saved (practiaclly nil), you would need to do this a lot to get any benefit. But were you to, increase memory footprints and more pagefaults(possibly ) could arise, slowing your program down again.
Long story short, if something is guarenteed to be faster in all situations, the compiler probably already does it. If it doesn't, then it may be a sign that its not such a good idea.
cheers.