Raised This Month: $ Target: $400
 0% 

Static vs New


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
PartialCloning
Senior Member
Join Date: Dec 2015
Old 12-06-2015 , 20:19   Static vs New
Reply With Quote #1

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?
PartialCloning is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 12-06-2015 , 20:56   Re: Static vs New
Reply With Quote #2

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
__________________

Last edited by Bugsy; 12-06-2015 at 21:06.
Bugsy is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


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


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