Quote:
Originally Posted by damage220
1. You should never use sizeof( in a loop condition. Create a variable and store the size in it.
|
That's the first time I've ever heard this in the 15 years I've been around here. I was under the impression that sizeof was evaluated at compile-time (except in specific use cases). I've only ever heard people say that you shouldn't use a function (sizeof is not a function, it's an operator) in a for or while loop's definition if the value will not change during the loop.
Quote:
Originally Posted by damage220
2. To speed up execution, move static arrays out to global scope, precache them.
|
This is not good advice. If something is only used in that function and has no usefulness to other areas of code, it should not be global (making a local variable/constant global just pollutes the global namespace).
If it's relatively small and the function is not called very often then it's generally negligible to declare it as "new". If it never changes then it should be declared as a constant ("const"). If it's a large variable (e.g. an array with a lot of cells) and it's not constant, it should be declared as a static variable ("static").
__________________