Reputation: 487
I'm working on a game, in one class I have for now 4 flags (I use boolean), but I'd like to switch to int and make each flag a bit. Some of my flags are checked inside the main loop every time, so looking to the future (where I could have more flags): will my flagset slow down my program? Is it better to keep using boolean?
Upvotes: 0
Views: 255
Reputation: 3902
It sounds as if you are quite a beginner. So here is what I'd advice you to do: Program your game and think about optimization only when you notice something like lagging. Otherwise, it's not that important. Focus on other things, such as readability and reusability of code.
Upvotes: 1
Reputation: 904
Optimization should hing only on how often you are actually going to use something. This is a big killer on programming efficiency. The way to determine IF you need to optimize something is figure out how often it will actually be used.
So, if you are only going to use something once or twice a second or when the user manually does something then the answer is most likely going to be "don't bother". On the other hand if the optimization is in something that runs continuously a thousand times a second then the answer is "maybe". The later depends on how many clocks the operation is eating. The case of flag checking the answer is most likely no as the clock ticks for either are negligible. The better optimization might be on why you are calling that function, routine, etc ... so many times to begin with.
Upvotes: 3