new VS static
I would like to know whether it is worth to use static instead of new? In what situations?
|
Re: new VS static
|
Re: new VS static
If it isn't being called more than 1 time per second the entire time the server is running, just use new.
|
Re: new VS static
hmm i was interested to find this out too
thank you |
Re: new VS static
static - declared only once.
new - declared everytime the word new is called. Use more memory. static is used in functions which get called a lot. Ex: client_prethink |
Re: new VS static
So what about when hooking eg. a weapon's fire event using Ham_Weapon_PrimaryAttack, and let's say you want to find the shooters id using pev_owner .... would you be better off to make it static id = pev() or new ?
|
Re: new VS static
Static variables seem to only be useful when you are using arrays in functions that are called very often, or when you want a global-type variable with only the local scope.
First example: Code:
It has to create and destroy those variables each call, and arrays make it even more expensive. Instead, this should be done: Code:
Second example: Code:
Could be changed to less code: Code:
It makes it easier to copy/paste simple functions into your own code that are useful without having to make sure you have the variables or extras added to plugin_init(). |
| All times are GMT -4. The time now is 14:34. |
Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.