Raised This Month: $ Target: $400
 0% 

Cvar and Pcvar


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Jhob94
AMX Mod X Donor
Join Date: Jul 2012
Old 05-10-2013 , 12:20   Cvar and Pcvar
Reply With Quote #1

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?
__________________
Jhob94 is offline
guipatinador
SourceMod Donner Party
Join Date: Oct 2009
Location: Poortugal
Old 05-10-2013 , 13:40   Re: Cvar and Pcvar
Reply With Quote #2

http://wiki.amxmodx.org/Optimizing_P...#Cvar_Pointers
guipatinador is offline
Arkshine
AMX Mod X Plugin Approver
Join Date: Oct 2005
Old 05-10-2013 , 14:06   Re: Cvar and Pcvar
Reply With Quote #3

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.
__________________
Arkshine is offline
Jhob94
AMX Mod X Donor
Join Date: Jul 2012
Old 05-10-2013 , 16:05   Re: Cvar and Pcvar
Reply With Quote #4

Quote:
Originally Posted by Arkshine View Post
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
__________________
Jhob94 is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 05-10-2013 , 16:25   Re: Cvar and Pcvar
Reply With Quote #5

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

Last edited by fysiks; 05-10-2013 at 16:25.
fysiks is offline
Reply


Thread Tools
Display Modes

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 10:54.


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