Bitwise Operation
Hey all!
So, I am trying to learn how to use bitwise operation as a replacement for booleans (ex. bool g_bEnabled[MAXPLAYERS+1]) (performance optimization). Here is something I have coded: PHP Code:
1.) Did I add and remove the client indexes correctly with the g_iClients variable? 2.) Would I use: Code:
g_iClients & client Code:
g_iClients & (1 << client) Thanks, Grant |
Re: Bitwise Operation
Just use arrays, it's okay.
|
Re: Bitwise Operation
You're or-ing multiple values with shared bits (look at a binary chart). You'd probably want to do (1 << client) every time you add / remove / check for a flag, but otherwise you're using the correct bitwise operations.
Really though, I've also considered doing this before. Just use an array for client indices. Pawn cells are 32-bit values, so your code would be broken on client indices greater than 31 (considering the first client index is 1 you're already not using the rightmost bit). Even TF2 has a high client iindex of 33 (34?) with SourceTV and/or Replay present and a raised maxplayers value. |
Re: Bitwise Operation
Quote:
Quote:
|
All times are GMT -4. The time now is 01:22. |
Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.