AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Static vs New (https://forums.alliedmods.net/showthread.php?t=275722)

PartialCloning 12-06-2015 20:19

Static vs New
 
I know this topic has been discussed many times and I did read about it, but I still don't understand the main difference on the lowest level.

Code:

static i;
for(i = 1; i <= 10; i++)

Code:

for(new i = 1; i <= 10; i++)
From my understanding, in the first case the value always remains in the memory, while in the second case it's removed as soon as it's not being used. Wouldn't that make 'new' better than 'static' in most cases? Besides when you need to hold the value? Or is the part that 'new' originally held no longer reusable?

Bugsy 12-06-2015 20:56

Re: Static vs New
 
There's plenty of literature out there as this is not specific to Pawn. If you are familiar with global variables, think of a static variable as a local global variable, having a local scope only to the function where it is declared.

https://en.wikipedia.org/wiki/Static_variable


All times are GMT -4. The time now is 18:10.

Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.