Original Post
🔒 Locked
static variables
Advertisement
if they are class instances and have constructors: statics will be faster, but you won't notice the difference unless construction is expensive
if they are built-in types or pod types: there will be no appreciable difference in performance
note that static variables make your function non-reentrable (it cannot call itself, directly or indirectly, and it cannot be executed by multiple threads simultaneously*).
use static variables when it makes sense, that is, when you want to persist state across function calls. be aware of restrictions that statics impose on the use of your function.
if you can choose between statics and locals, go for locals. it will make your code more usable (see above) if you or someone using your code ever want to use recursion or multithreading.
* unless calls are synchronized.
[edited by - niyaw on January 29, 2003 1:13:13 AM]
if they are built-in types or pod types: there will be no appreciable difference in performance
note that static variables make your function non-reentrable (it cannot call itself, directly or indirectly, and it cannot be executed by multiple threads simultaneously*).
use static variables when it makes sense, that is, when you want to persist state across function calls. be aware of restrictions that statics impose on the use of your function.
if you can choose between statics and locals, go for locals. it will make your code more usable (see above) if you or someone using your code ever want to use recursion or multithreading.
* unless calls are synchronized.
[edited by - niyaw on January 29, 2003 1:13:13 AM]
Topic Locked
This topic has been locked by a moderator. New replies are not allowed.
Sign in to reply to this topic.
Advertisement