Hi Nuke,
This is big trade off, that ultimately might not make much difference in your performance.
The super low level view is that the compiler often assigns bools to a much larger memory space since it is “generally” faster on most processors architectures.
The thinking is then, since we know the extra memory is assigned anyway, its possible to just use a value type that allows us to use all that extra space, essentially for free in terms of actual memory usage.
If your trying to save every bit, say for network transfer, using bit masks are the way to go.
Using bit masks allows us to pack more True/False data into the same memory chunk.
Ref: c++ - How can I use a bitmask? - Stack Overflow
The big downside to this is the mental power needed to know what the bit masks are and how they are used.
in your example
uint32 bDisabled : 1;
your variable name is somewhat clear, I would assume the whole object is disabled if this value is false, but that could be completely wrong. Since the first b in bDisabled is Hungarian notation for bool, using bit flags would be even more unexpected.
As a rule of thumb: Avoid using magic numbers IE: int thisObjectsState = 41; // what is 41, do you know? will you remember after a month?
enum ActorStateFlags {
DISABLED = 1 << 0, 2^0
ONFIRE = 1 << 1, 2^1
FLAGSupTooFor32uint32 = 1 <<31,
}
uint32 ActorStates: DISABLED ;
uint32 ActorStates2: DISABLED | ONFIRE ;
But that is a whole lot of extra work when your code is probably good enough and fast enough, just using
bool isDisabled: true; // By limiting the choices for isDisabled to two values, the mental overhead is reduced.
There are a lot of ways to solve problems with code, if it works for you great. Coding speed can be better then code quality is some cases, actually completing a game vs giving up. But if your planning to invest significant time making a complex game, the investment in easy to understand code will pay itself back.