SA-MP Forums Archive
static - 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: static (/showthread.php?tid=615784)



static - Micko123 - 27.08.2016

I wanted to ask you guys something. Which one is faster and better to use
PHP код:
new string[128];
or
static 
string[128]; 



Re: static - IFilip - 27.08.2016

The first, sure.
NEW = https://en.wikipedia.org/wiki/Memory_management#DYNAMIC
STATIC = https://en.wikipedia.org/wiki/Static_variable


Re: static - DeeadPool - 27.08.2016

new is suggested more.


Re: static - PrO.GameR - 27.08.2016

Neither (or rather negligible?), static stays in memory for further usage, while everytime you leave the code block a variable belongs to, a 'new' variable gets removed from memory, therefore re-allocating that space every time you call it.
Statics are mostly used when the code is under a heavily repetitive callback, so it won't remove and recreate the var 20 times a sec for example.

As a rule of thumb, if you don't know why static is useful here, just don't use it, use new everywhere!


Re: static - Micko123 - 27.08.2016

Got it. Thank you


Re: static - SickAttack - 27.08.2016

Also: static variables can't be used outside the file.