Raised This Month: $ Target: $400
 0% 

Solved When should i use "static" over "new" variable?


Post New Thread Reply   
 
Thread Tools Display Modes
klippy
AlliedModders Donor
Join Date: May 2013
Location: Serbia
Old 03-04-2018 , 13:22   Re: When should i use "static" over "new" variable?
Reply With Quote #11

Quote:
Originally Posted by HamletEagle View Post
Step 1: new array[1000] in prethink
Step 2: enjoy.
The posted specifically wrote "new var" so I assumed it's a single cell.

Also even with 1000 you won't notice any difference, a memset for 4KB of memory takes no time. I feel like people here are often underestimating Pawn. That's why we use Pawn over C - because simplicity is worth the loss in performance.
By the way I don't say you should use new instead of static in that case, but I see people going crazy about some stuff regarding performance here.
__________________
klippy is offline
HamletEagle
AMX Mod X Plugin Approver
Join Date: Sep 2013
Location: Romania
Old 03-04-2018 , 13:37   Re: When should i use "static" over "new" variable?
Reply With Quote #12

Quote:
Originally Posted by KliPPy View Post
The posted specifically wrote "new var" so I assumed it's a single cell.

Also even with 1000 you won't notice any difference, a memset for 4KB of memory takes no time. I feel like people here are often underestimating Pawn. That's why we use Pawn over C - because simplicity is worth the loss in performance.
By the way I don't say you should use new instead of static in that case, but I see people going crazy about some stuff regarding performance here.
I'm not necessarily talking about performance, it's more about learning how to do things the proper way. If you get into the habit of not caring how much memory you allocate, or how much resources in general the code is using it will lead at some point to very bad things.

To be clear, I'm not talking about micro optimizations, I'm just advocating that things should be done in the proper way. Just because in this specific case nothing bad happened doesn't mean it won't ever happen.
__________________

Last edited by HamletEagle; 03-04-2018 at 13:39.
HamletEagle is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 03-04-2018 , 16:20   Re: When should i use "static" over "new" variable?
Reply With Quote #13

Quote:
Originally Posted by Syturi0 View Post
And not a single one explains it properly.
You need to try harder. 30 seconds got me to this, this, and this.

P.S. There were several more, several of them linked to one of these.
P.P.S. If you are curious, I searched for the term "static" (actually searched "new static" but it filtered out "new") in titles only in the Scripting Help section. This led me to several threads that specifically asked about static vs new.
__________________

Last edited by fysiks; 03-04-2018 at 16:22.
fysiks 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 07:27.


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