Raised This Month: $12 Target: $400
 3% 

getting cvar string/num, which is faster?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Desikac
Senior Member
Join Date: Apr 2010
Location: Serbia
Old 08-28-2011 , 17:54   getting cvar string/num, which is faster?
Reply With Quote #1

Method 1: (get_cvar)
PHP Code:
#include <amxmodx>

public plugin_init() {
    
register_cvar("mycvar""1"//num
    
register_cvar("myothercvar""something"//string
}

public 
get_values() {
    new 
cvar[32]
    
get_cvar_string("myothercvar"cvar31)
    
//and
    
new cvarnum get_cvar_num("mycvar")

Method 2: (get_pcvar , get_cvar_pointer)
PHP Code:
#include <amxmodx>

public plugin_init() {
    
register_cvar("mycvar""1"//num
    
register_cvar("myothercvar""something"//string
}

public 
get_values() {
    new 
cvar[32]
    
get_pcvar_string(get_cvar_pointer("myothercvar"), cvar31)
    
    new 
cvarnum get_pcvar_num(get_cvar_pointer("mycvar"))

Method 3: (variables for cvars, get_pcvar)
PHP Code:
#include <amxmodx>

new cvar
new othercvar

public plugin_init() {
    
cvar register_cvar("mycvar""1"//num
    
othercvar register_cvar("myothercvar""something"//string
}

public 
get_values() {
    new 
cvars[32]
    
get_pcvar_string(othercvarcvars31)
    
//and
    
new cvarnum get_pcvar_num(cvar)

I'm using method 1 and want to optimize it a bit and use method 2. Is method 3 better than method 2?
Desikac is offline
Send a message via MSN to Desikac Send a message via Skype™ to Desikac
Hunter-Digital
Veteran Member
Join Date: Aug 2006
Location: In the Game [ro]
Old 08-28-2011 , 17:59   Re: getting cvar string/num, which is faster?
Reply With Quote #2

Saving cvar pointer and retrieving with get_pcvar_* is the best method.

get_cvar_* functions are verry slow in comparison.
__________________
Hunter-Digital is offline
OvidiuS
Chillaxin'
Join Date: Dec 2009
Location: Serbia
Old 08-28-2011 , 18:09   Re: getting cvar string/num, which is faster?
Reply With Quote #3

http://forums.alliedmods.net/showpos...1&postcount=17
OvidiuS is offline
Send a message via Skype™ to OvidiuS
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 08-28-2011 , 20:28   Re: getting cvar string/num, which is faster?
Reply With Quote #4

Method 2 is actually the worst of the three.
__________________
fysiks is offline
ConnorMcLeod
Veteran Member
Join Date: Jul 2006
Location: France (95)
Old 08-29-2011 , 00:52   Re: getting cvar string/num, which is faster?
Reply With Quote #5

Method 3 is completely incorrect, can't see what you are trying to do.
__________________
- tired and retired -

- my plugins -
ConnorMcLeod is offline
Arkshine
AMX Mod X Plugin Approver
Join Date: Oct 2005
Old 08-29-2011 , 04:10   Re: getting cvar string/num, which is faster?
Reply With Quote #6

Method 4 : using Cvar Utilities.

Code:
#include <amxmodx> #include <cvar_util> new HandleCvarMyCvar; new HandleCvarOther; new CvarNumber; new CvarString[ 32 ]; public plugin_init() {     HandleCvarMyCvar = CvarRegister( "mycvar", "1" );     HandleCvarOther  = CvarRegister( "myothercvar", "something" );         CvarHookChangeAll( "OnCvarChange" ); } public OnCvarChange( const handleCvar, const oldValue[], const newValue[], const cvarName[] ) {     if( handleCvar == HandleCvarMyCvar )     {         CvarNumber = str_to_num( newValue );     }     else if( handleCvar == HandleCvarOther )     {         copy( CvarString, charsmax( CvarString ), newValue );     } }
__________________

Last edited by Arkshine; 08-29-2011 at 04:26.
Arkshine is offline
abdul-rehman
Veteran Member
Join Date: Jan 2010
Location: Khi, Pakistan
Old 08-29-2011 , 04:22   Re: getting cvar string/num, which is faster?
Reply With Quote #7

Is it me or you should do it like this:
Code:
public OnCvarChange( const handleCvar, const oldValue[], const newValue[], const cvarName[] ) {     if( HandleCvarMyCvar == handleCvar)     {         CvarNumber = str_to_num( newValue );     }     else if( HandleCvarOther == handleCvar)     {         copy( CvarString, charsmax( CvarString ), newValue );     } }
__________________

My Plugins For ZP

Inactive due to College and Studies
abdul-rehman is offline
Send a message via Yahoo to abdul-rehman Send a message via Skype™ to abdul-rehman
Arkshine
AMX Mod X Plugin Approver
Join Date: Oct 2005
Old 08-29-2011 , 04:27   Re: getting cvar string/num, which is faster?
Reply With Quote #8

Oops. Typing too fastly. Fixed.
__________________
Arkshine is offline
OvidiuS
Chillaxin'
Join Date: Dec 2009
Location: Serbia
Old 08-29-2011 , 05:05   Re: getting cvar string/num, which is faster?
Reply With Quote #9

Quote:
Originally Posted by Arkshine View Post
Method 4 : using Cvar Utilities.

Code:
#include <amxmodx> #include <cvar_util> new HandleCvarMyCvar; new HandleCvarOther; new CvarNumber; new CvarString[ 32 ]; public plugin_init() {     HandleCvarMyCvar = CvarRegister( "mycvar", "1" );     HandleCvarOther  = CvarRegister( "myothercvar", "something" );         CvarHookChangeAll( "OnCvarChange" ); } public OnCvarChange( const handleCvar, const oldValue[], const newValue[], const cvarName[] ) {     if( handleCvar == HandleCvarMyCvar )     {         CvarNumber = str_to_num( newValue );     }     else if( handleCvar == HandleCvarOther )     {         copy( CvarString, charsmax( CvarString ), newValue );     } }
he has around 22 cvars xD
anything more adjustable?
OvidiuS is offline
Send a message via Skype™ to OvidiuS
abdul-rehman
Veteran Member
Join Date: Jan 2010
Location: Khi, Pakistan
Old 08-29-2011 , 06:18   Re: getting cvar string/num, which is faster?
Reply With Quote #10

That module is quite useful, he should use it if he can.
__________________

My Plugins For ZP

Inactive due to College and Studies
abdul-rehman is offline
Send a message via Yahoo to abdul-rehman Send a message via Skype™ to abdul-rehman
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 14:52.


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