View Single Post
Hawk552
AMX Mod X Moderator
Join Date: Aug 2005
Old 06-27-2006 , 09:37   Re: The Use of Static Variables
Reply With Quote #4

Quote:
Originally Posted by Cheap_Suit
hmmm interesting...

Can you tell me when to use it and when not to use it
Well, in something like a loop, it's pretty useless, like this:

Code:
for(static iCount = 0;iCount < x;iCount++)

You'd might as well use new, because the = 0 section of it will make it the same expensiveness as using new. This goes for most other things like = get_user_frags(id) etc.

When using a huge ass array like a motd or menu it's generally best to use static because arrays are a huge hit on CPU, and making it static nullifies that. You must be careful about re-entrancy though, as in something being set from the last time it was used and using it for this instance anyway. If your script is enormous you might start running out of memory in which case you can use #pragma dynamic, with some value like 131072 (which is in bytes)

But as shown in my example one of the best ways to use this is something like:

Code:
static szName[33] get_user_name(id,szName,32)
__________________
Hawk552 is offline
Send a message via AIM to Hawk552