Aerosol Posted April 3, 2007 Report Share Posted April 3, 2007 Which is more stable when detecting states? Counters or flags? for example, i could use a counter and set it's value for 0 for on the ground, and 1 for in the air. But I could also use a flag and it's on and off states for the same thing. So which is more stable? Link to comment Share on other sites More sharing options...
ssbfalcon Posted April 3, 2007 Report Share Posted April 3, 2007 No real difference, other than you can use counters to detect more than 2 states... Just make sure you don't toggle the flag and just set them directly... Link to comment Share on other sites More sharing options...
Damizean Posted April 3, 2007 Report Share Posted April 3, 2007 In terms of stability they should be the same Link to comment Share on other sites More sharing options...
Blue Frenzy Posted April 3, 2007 Report Share Posted April 3, 2007 They are basically the same. Flags are faster to use, and probably in memory too, while values can have names and multiple values. If you only have the on and off status, i'd recomend to use flags if you are not going to use too many, or it could be confusing. Link to comment Share on other sites More sharing options...
Smidge204 Posted April 3, 2007 Report Share Posted April 3, 2007 I'm willing to bet that both flags and coutners use 32bit integers (Unless counters support decimals, then it might be different) In terms of processing, flags might be slightly faster since teh value is implied rather than explicit (meaning to test a counter, you have to explicitly load a value to compare it to). Modern CPUs use pipelining and caching so there is no difference anyway, but MMF's virtual machine may not be as efficient. Easy way to test: Write a tight loop and do, say, 10,000 flag read/writes and compare the execution time to the same number of counter read/writes. =Smidge= Link to comment Share on other sites More sharing options...
MidimanNull Posted April 3, 2007 Report Share Posted April 3, 2007 Use a counter to track whatever value, and also have that counter use its own flags ( which they have ). 2 birds, 1 stone. Link to comment Share on other sites More sharing options...
Recommended Posts