Raised This Month: $ Target: $400
 0% 

g[s]et_cvar and g[s]et_pcvar


  
 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
Twilight Suzuka
bad
Join Date: Jul 2004
Location: CS lab
Old 11-07-2007 , 03:45   Re: g[s]et_cvar and g[s]et_pcvar
Reply With Quote #15

How about just using the ACTUAL CASE, instead of making a lot of confusing and stupid analogies?

The CVAR structure is an enormous linked list, meaning that every time you use the normal syntax for getting CVAR's, you have the potential to force the server to check every single CVAR. This is O(N) performance, or linear, and is absolutely terrible.

The server itself registers lots of CVAR's, other plugins register CVAR's, and your plugin registers CVAR's. This means that your one little call to find a CVAR's value could very well be hundreds of string comparisons and indirections (and usually is).

However, if you use the pointer syntax, you reduce this huge overhead to a single indirection, O(1) performance, which is the best performance possible, and worlds better than the other syntax.

You waste 1 cell of memory, 4 bytes, in order to reduce an operation which is potentially hundreds of string comparisons, hundreds of indirections, and millions of cycles, to a single indirection, perhaps a hundred cycles, less if it is in cache.

Save a million cycles, waste 4 bytes, make your code a little more complex.

This isn't about a memory / speed tradeoff. Trade off implies that there is some benefit either way over the other. There is absolutely no benefit to saving 4 bytes today, even on the smallest of microprocessors, if it means wasting potentially millions of cycles.
__________________

Last edited by Twilight Suzuka; 11-07-2007 at 03:54.
Twilight Suzuka is offline
Send a message via AIM to Twilight Suzuka Send a message via MSN to Twilight Suzuka
 



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 11:13.


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