SA-MP Forums Archive
Variables - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Variables (/showthread.php?tid=328451)



Variables - DRIFT_HUNTER - 24.03.2012

Just a simple and stupid question:
Is it better to create global variable and use it for formatting messages or create one just when i need it?


Re: Variables - The DeLuca - 25.03.2012

Depends if the same variable is called multiple times in the script or not. Like if you're saving the server time, or mode then you should make it global where as if it's just for a sethealth function its easier to keep it when needed.


Re: Variables - MP2 - 25.03.2012

Quote:
Originally Posted by ******
Globals are ALWAYS allocated, no matter how often you use them. Locals have memory allocated on, and freed from, the stack as and when (and if) it's needed. What's more, using locals reduces the number of bugs caused by functions accessing the same variables and "pollutes" the global namespace less, making naming collisions less likely. If you really want to statically allocate all your arrays, use static locals rather than full globals.
Quote:
Originally Posted by ******
Locals are always better than globals (you can increase stack space if you need).
From ****** himself.