Jump to content
A 2021 backup has been restored. Forums are closed and work in progress. Join our Discord server for more updates! ×
SoaH City Message Board

flags vs counters


Aerosol

Recommended Posts

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

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

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

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...