AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   g[s]et_cvar and g[s]et_pcvar (https://forums.alliedmods.net/showthread.php?t=62718)

l4ulwtlln 11-03-2007 14:11

g[s]et_cvar and g[s]et_pcvar
 
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

Alka 11-03-2007 14:13

Re: g[s]et_cvar and g[s]et_pcvar
 
g[s]et_pcvar is a pointer for cvars and is much faster!

Arkshine 11-03-2007 15:16

Re: g[s]et_cvar and g[s]et_pcvar
 
http://wiki.alliedmods.net/Optimizin...#Cvar_Pointers

l4ulwtlln 11-03-2007 22:13

Re: g[s]et_cvar and g[s]et_pcvar
 
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")



M249-M4A1 11-04-2007 00:35

Re: g[s]et_cvar and g[s]et_pcvar
 
The first one.

Emp` 11-04-2007 01:58

Re: g[s]et_cvar and g[s]et_pcvar
 
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")
}


Greenberet 11-04-2007 09:47

Re: g[s]et_cvar and g[s]et_pcvar
 
Quote:

Originally Posted by Emp` (Post 549223)
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).

_Master_ 11-05-2007 03:27

Re: g[s]et_cvar and g[s]et_pcvar
 
I've said this before and I'll say it again:
You should allways optimize for speed rather than memory consumption.

l4ulwtlln 11-05-2007 19:13

Re: g[s]et_cvar and g[s]et_pcvar
 
does the speed much that much of a difference?

M249-M4A1 11-05-2007 22:36

Re: g[s]et_cvar and g[s]et_pcvar
 
Quote:

Originally Posted by l4ulwtlln (Post 549931)
does the speed much that much of a difference?

Of course!


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

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