Raised This Month: $ Target: $400
 0% 

g[s]et_cvar and g[s]et_pcvar


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
l4ulwtlln
Member
Join Date: Aug 2007
Old 11-03-2007 , 14:11   g[s]et_cvar and g[s]et_pcvar
Reply With Quote #1

in general which is better to use?

i know that as of 1.80 g[s]et_pcvar has all the functions as g[s]et_cvar so this should not be a factor
l4ulwtlln is offline
Alka
AMX Mod X Plugin Approver
Join Date: Dec 2006
Location: malloc(null)
Old 11-03-2007 , 14:13   Re: g[s]et_cvar and g[s]et_pcvar
Reply With Quote #2

g[s]et_pcvar is a pointer for cvars and is much faster!
__________________
Still...lovin' . Connor noob! Hello
Alka is offline
Arkshine
AMX Mod X Plugin Approver
Join Date: Oct 2005
Old 11-03-2007 , 15:16   Re: g[s]et_cvar and g[s]et_pcvar
Reply With Quote #3

http://wiki.alliedmods.net/Optimizin...#Cvar_Pointers
__________________
Arkshine is offline
l4ulwtlln
Member
Join Date: Aug 2007
Old 11-03-2007 , 22:13   Re: g[s]et_cvar and g[s]et_pcvar
Reply With Quote #4

yes i know it is faster but for that speed you are sacrificing memory, or at least that is what ive read.


okay lets put it this way.
i kno that if u use it for multiple functions then pcvar is the way to go but is it better than using cvar with 1 function?




which example is better?:
PHP Code:
new test_pcvar

public plugin_init()
{
    
register_plugin("test""""")
    
test_pcvar register_cvar("amx_test_cvar""1")
}

public 
client_putinserver(id)
{
    if (
get_pcvar_num(test_pcvar))
        
client_print(0print_chat"test")

or

PHP Code:
public plugin_init()
{
    
register_plugin("test""""")
    
register_cvar("amx_test_cvar""1")
}

public 
client_putinserver(id)
{
    if (
get_cvar_num("amx_test_cvar"))
        
client_print(0print_chat"test")


Last edited by l4ulwtlln; 11-03-2007 at 22:17.
l4ulwtlln is offline
M249-M4A1
I <3 Mac
Join Date: May 2005
Location: Not interested
Old 11-04-2007 , 00:35   Re: g[s]et_cvar and g[s]et_pcvar
Reply With Quote #5

The first one.
__________________
M249-M4A1 is offline
Emp`
AMX Mod X Plugin Approver
Join Date: Aug 2005
Location: Decapod 10
Old 11-04-2007 , 01:58   Re: g[s]et_cvar and g[s]et_pcvar
Reply With Quote #6

if you really wanted to optimize it, you could just do:
Code:
public plugin_init()
{
    register_plugin("test", "", "")
}

public client_putinserver(id)
{
    static test_pcvar;
    if( !test_pcvar )
        test_pcvar = register_cvar("amx_test_cvar", "1")
    if (get_pcvar_num(test_pcvar))
        client_print(0, print_chat, "test")
}
Emp` is offline
Send a message via AIM to Emp` Send a message via MSN to Emp` Send a message via Yahoo to Emp` Send a message via Skype™ to Emp`
Greenberet
AMX Mod X Beta Tester
Join Date: Apr 2004
Location: Vienna
Old 11-04-2007 , 09:47   Re: g[s]et_cvar and g[s]et_pcvar
Reply With Quote #7

Quote:
Originally Posted by Emp` View Post
if you really wanted to optimize it, you could just do:
Code:
public plugin_init()
{
    register_plugin("test", "", "")
}

public client_putinserver(id)
{
    static test_pcvar;
    if( !test_pcvar )
        test_pcvar = register_cvar("amx_test_cvar", "1")
    if (get_pcvar_num(test_pcvar))
        client_print(0, print_chat, "test")
}
thats not better.

memory usage to his pcvar example: identical
performance: worst. you check everytime in client_putinserver if the cvar is registered which will cost performance(not much, but it costs performance).
__________________
Greenberet is offline
Send a message via ICQ to Greenberet Send a message via MSN to Greenberet
_Master_
Senior Member
Join Date: Dec 2006
Old 11-05-2007 , 03:27   Re: g[s]et_cvar and g[s]et_pcvar
Reply With Quote #8

I've said this before and I'll say it again:
You should allways optimize for speed rather than memory consumption.
_Master_ is offline
l4ulwtlln
Member
Join Date: Aug 2007
Old 11-05-2007 , 19:13   Re: g[s]et_cvar and g[s]et_pcvar
Reply With Quote #9

does the speed much that much of a difference?
l4ulwtlln is offline
M249-M4A1
I <3 Mac
Join Date: May 2005
Location: Not interested
Old 11-05-2007 , 22:36   Re: g[s]et_cvar and g[s]et_pcvar
Reply With Quote #10

Quote:
Originally Posted by l4ulwtlln View Post
does the speed much that much of a difference?
Of course!
__________________
M249-M4A1 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 21:57.


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