AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Cvar and Pcvar (https://forums.alliedmods.net/showthread.php?t=215635)

Jhob94 05-10-2013 12:20

Cvar and Pcvar
 
Well in biggest part i use pcvar and not cvar.
But i dont understand why pcvar is more efficient then cvar.
Can someone explain me?

guipatinador 05-10-2013 13:40

Re: Cvar and Pcvar
 
http://wiki.amxmodx.org/Optimizing_P...#Cvar_Pointers

Arkshine 05-10-2013 14:06

Re: Cvar and Pcvar
 
In a fast and simplistic explanation : when you register a cvar, this one is saved in a big list. To access to a specific cvar of this list, you need to search by the cvar name, so comparing each name, until you find the one you want do do things. It's a slow process. Instead, you could point directly on a cvar, like in Pawn you would know the index of an array, here it's not an index, but more a "pointer". That's the point of using pcvar (p for pointer). You don't need to know what is really a pointer in C (that's something you can search). So : get_cvar_* will search by name in the big list to know the "pointer" , get_pcvar_* will access directly to the "pointer" in memory ; that's why it's way faster.

Jhob94 05-10-2013 16:05

Re: Cvar and Pcvar
 
Quote:

Originally Posted by Arkshine (Post 1949452)
In a fast and simplistic explanation : when you register a cvar, this one is saved in a big list. To access to a specific cvar of this list, you need to search by the cvar name, so comparing each name, until you find the one you want do do things. It's a slow process. Instead, you could point directly on a cvar, like in Pawn you would know the index of an array, here it's not an index, but more a "pointer". That's the point of using pcvar (p for pointer). You don't need to know what is really a pointer in C (that's something you can search). So : get_cvar_* will search by name in the big list to know the "pointer" , get_pcvar_* will access directly to the "pointer" in memory ; that's why it's way faster.

Perfect, thanks :up:

fysiks 05-10-2013 16:25

Re: Cvar and Pcvar
 
Here is a good yet whimsical analogy by Joaquim: https://forums.alliedmods.net/showpo...52&postcount=7


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

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