Raised This Month: $32 Target: $400
 8% 

New API and Syntax


Post New Thread Reply   
 
Thread Tools Display Modes
Fyren
FyrenFyrenFyrenFyrenFyren FyrenFyrenFyrenFyrenFyren FyrenFyrenFyrenFyrenFyren FyrenFyrenFyrenFyrenFyren
Join Date: Feb 2106
Old 03-21-2017 , 05:28   Re: New API and Syntax
Reply With Quote #861

Quote:
Originally Posted by Timocop View Post
Will 'decl' have a comeback or is there a heuristic in the compiler now?
No to both.
Fyren is offline
Timocop
AlliedModders Donor
Join Date: Mar 2013
Location: Germany
Old 03-21-2017 , 06:55   Re: New API and Syntax
Reply With Quote #862

Nah i'm just curious. I thought there is somekind of optimization heuristic for that in the new compiler.
I'm already using static everywhere, literally. Even micro optimizations. Because i'm using a vServer with dedicated servers on it.
Timocop is offline
nergal
Veteran Member
Join Date: Apr 2012
Old 03-21-2017 , 15:11   Re: New API and Syntax
Reply With Quote #863

Quote:
Originally Posted by Timocop View Post
Nah i'm just curious. I thought there is somekind of optimization heuristic for that in the new compiler.
I'm already using static everywhere, literally. Even micro optimizations. Because i'm using a vServer with dedicated servers on it.
decl is deprecated because EVERY variable you declare is auto initialized to 0.
same with arrays I believe.
__________________
nergal is offline
404UserNotFound
BANNED
Join Date: Dec 2011
Old 03-21-2017 , 15:57   Re: New API and Syntax
Reply With Quote #864

Quote:
Originally Posted by ddhoward View Post
The consensus is that decl is pretty pointless, is dangerous, was a mistake to have implemented into SourcePawn in the first place, and if what you're doing actually requires decl to perform adequately, then an alternative to what you're doing should be found (such as making the variable static/global if possible, etc.)
decl was also something that threw me off when I first started doing this stuff. I never did understand or learn when to use it and when not to.

EDIT: Ah, auto-initialization of variables to 0. Makes sense given I remember reading something about variables containing "trash" data somehow in regards to initialization.

Last edited by 404UserNotFound; 03-21-2017 at 15:59.
404UserNotFound is offline
Timocop
AlliedModders Donor
Join Date: Mar 2013
Location: Germany
Old 03-22-2017 , 04:02   Re: New API and Syntax
Reply With Quote #865

Quote:
Originally Posted by nergal View Post
decl is deprecated because EVERY variable you declare is auto initialized to 0.
same with arrays I believe.
If you use decl, they dont. decl just allocates memory but doesnt set it, i think malloc() in C++ is the closest example. But yea, static/global variables is still best for large arrays (because it has no initialization process).
Here the differences in assembly:

Decl (Stack)
Spoiler
New (Stack)
Spoiler

Static (Stack)
Spoiler
Timocop is offline
headline
SourceMod Moderator
Join Date: Mar 2015
Old 03-22-2017 , 04:20   Re: New API and Syntax
Reply With Quote #866

Quote:
EDIT: Ah, auto-initialization of variables to 0. Makes sense given I remember reading something about variables containing "trash" data somehow in regards to initialization.
Exactly. The trash data is just what happened to occupy that space at the time. Thus, "garbage"

Last edited by headline; 03-22-2017 at 04:21.
headline is offline
nergal
Veteran Member
Join Date: Apr 2012
Old 03-25-2017 , 17:55   Re: New API and Syntax
Reply With Quote #867

Quote:
Originally Posted by Headline View Post
Exactly. The trash data is just what happened to occupy that space at the time. Thus, "garbage"
not a big deal, anyone coding with C/Assembler/C++ have learned to deal with garbage values.
Especially after creating (pointer) variables without initializing their new values.
__________________
nergal is offline
nergal
Veteran Member
Join Date: Apr 2012
Old 04-07-2017 , 21:08   Re: New API and Syntax
Reply With Quote #868

idea in terms of removing/reducing use of global variables.

Obviously to use data from each forward/event functions, we have to put variables to a global scope.

Why not have the option to be able to pass data similar to how GTK3+ does?
https://developer.gnome.org/gobject/...signal-connect

you hook to a signal aka forward and pass data to it? Similar to timers using datapacks, passing multiple data can be done using handles.
__________________

Last edited by nergal; 04-07-2017 at 21:09.
nergal is offline
BassPower
Member
Join Date: Mar 2011
Location: Lithuania
Old 05-11-2017 , 07:37   Re: New API and Syntax
Reply With Quote #869

how change to new syntax:
public void OnAutoUpdateChange(Handle conVar, const char[] oldVal, const char[] newVal)
{
g_bAutoUpdate = bool StringToInt(newVal);
}

g_bAutoUpdate = bool StringToInt(newVal); no compile
BassPower is offline
WildCard65
Veteran Member
Join Date: Aug 2013
Location: Canada
Old 05-11-2017 , 07:40   Re: New API and Syntax
Reply With Quote #870

view_as<bool>(StringToInt(newVal));
__________________
WildCard65 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 12:54.


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