Raised This Month: $32 Target: $400
 8% 

Magical MaxClients variable.


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Kigen
BANNED
Join Date: Feb 2008
Old 01-28-2009 , 14:07   Magical MaxClients variable.
Reply With Quote #1

Is this magical MaxClients variable an actual variable or a function call?

Hopefully, it functions like a variable for performance reasons. I wanna know because I'm updating some plugins that use GetMaxClients() and was figuring if MaxClients is a variable I can kill having to store GetMaxClients()'s value and just use MaxClients in the for loops.
Kigen is offline
bl4nk
SourceMod Developer
Join Date: Jul 2007
Old 01-28-2009 , 15:51   Re: Magical MaxClients variable.
Reply With Quote #2

MaxClients is a variable that is updated on map change.
bl4nk is offline
BAILOPAN
Join Date: Jan 2004
Old 01-28-2009 , 17:39   Re: Magical MaxClients variable.
Reply With Quote #3

Yes, MaxClients was introduced for two reasons:

1) To automatically propagate GetMaxClients() changes without any extra code needed. This can happen on map change but that's not guaranteed - it can happen at any time in theory.

2) Performance. It's around 27 instructions to enter GetMaxClients just from the VM overhead of "context" switching from the VM state to the machine state. As a variable it's about 2-3 instructions. (note: overhead of entering natives is usually drowned out by the gain in perf from a C++ optimizer on natives, something proven by benchmarks, but in cases like this it's excessive)

These are directly related since people were inappropriately caching the value to get performance - now that shouldn't be an issue.

Last edited by BAILOPAN; 01-28-2009 at 17:42.
BAILOPAN 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 17:20.


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