Variables
#1

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?
Reply
#2

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.
Reply
#3

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.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)