View Single Post
PM
hello, i am pm
Join Date: Jan 2004
Location: Canalization
Old 06-30-2006 , 06:57   Re: The Use of Static Variables
Reply With Quote #9

Quote:
Originally Posted by Hawk552
Which is what I said, because setting it after makes it take pretty much the same CPU as using the new operator. On top of that it just kind of sits around even after the function is used, which is kind of a waste of memory, even if it's only 4/8 bytes.
Just a technical note: It sits around even before the function is used. Static variables in PAWN (and in all C/C++ implementations I know as well) are implemented exactly as global variables, as you said. In the case of PAWN, this means that they are stored in the DAT section, which is always present in its entirety. As you said, the only difference is that the scope of the variable is different (for the compiler, not the abstract machine). You cannot access a static variable defined in one function from another function, while global variables are that; global. However note that you can modify the static variable from another function using "inline assembly" ( #emit compiler directive ) if you know its location in the DAT section (which you can find out by counting or more easily by disassembling the output .amxx file), but you would only do this if you are insane.
__________________
hello, i am pm

Last edited by PM; 06-30-2006 at 08:33.
PM is offline