static
#1

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

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

new is suggested more.
Reply
#4

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!
Reply
#5

Got it. Thank you
Reply
#6

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


Forum Jump:


Users browsing this thread: 1 Guest(s)