Another efficiency questoin
This is probably silly. But which is faster. Checking, then setting if it needs to be. Or just setting the value to what it needs to be. See following code examples.
PHP Code:
PHP Code:
It should also be noted that it is most likely to be false anyway. |
Re: Another efficiency questoin
First one .. or use bit-fields and just do var = 0 (no loop needed) .. or use arrayset
|
Re: Another efficiency questoin
Quote:
As for using bit-fields. could you show me an example that would be faster than arrayset? Mostly because i do want to be able to use bitsums more, i just don't feel adequately comfortable with them. |
Re: Another efficiency questoin
Here's a good read to get started.
Edit: Let me re-phrase, you have 32 booleans to work with in a single cell. You can also store other values but you're limited to the number of bits needed to represent the value. ie. 32 numbers ranging from 0-1 16 numbers ranging from 0-3 8 numbers ranging from 0-15 4 numbers ranging from 0-255 2 numbers ranging from 0-65535 |
Re: Another efficiency questoin
Thanks man!
As for arrayset....it looks like it doesn't work with a matrix (which is required for this) so i guess i'm going to have to go back to loop till i figure out a clever way of using bits. |
Re: Another efficiency questoin
Multi-dimension array?
PHP Code:
|
Re: Another efficiency questoin
I don't quite understand that example....how would i do it setting all cells in x column? matrix[-set-][X]
In other words....how do i apply it to my above loop? Trying it out these do not compile... Code:
arrayset(blockList[id][], false, sizeof(blockList[id]) )Error: Invalid expression, assumed zero on line 127 line 127 being the arrayset line. EDIT: *facepalm* arrayset(blockList[id], false, 33 ) works.... |
Re: Another efficiency questoin
You should never check a variable's value if you are going to set it to the same value regardless anyways. You are actually increasing the number of times memory is accessed.
|
Re: Another efficiency questoin
My fault liverwiz, my code was partially wrong, fixed. Use sizeof.
|
Re: Another efficiency questoin
Quote:
now....question. What if i use g_maxClients instead of sizeof? Would the difference in iterations be irrelevant? Would it simply not work? Or am i just being silly? I ask because its kinda hard to fill a test server to try out the last spot. |
| All times are GMT -4. The time now is 05:51. |
Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.