Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

DrEvil

Bit flags

This topic is 5281 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Suppose you needed a bunch of bit flags for something that went well over the size of an integer or something, and for memory concerns wanted to store them using bits instead of the normal byte bools. consider struct flags { bool flag:1; }; This would allocate 1 bit for the flag variable right? Now, would the compiler pad the structure with extra stuff for alignment, therefor defeating the purpose of trying to use 1 bit, or would the struct be 1 bit. I want to be able to track a large number of flags, using 1 bit, and would need the ability to add them as needed. I''m pondering something like enum flagEnum { flag1, flag2, flag3, flag4, max_flags, }; and then later doing struct flags[max_flags]; And I''m wondering if this method would do the flags at the bit level, or if padding or some other reason would be a problem.

Share this post


Link to post
Share on other sites
Advertisement
This wouldn''t work, the struct will be at least 1 byte (probably 4). If you have multiple flags like this you need to do something like this:

struct flags_t
bool flag1 : 1;
bool flag2 : 1;
bool flag3 : 1;
bool flag4 : 1;
} flags;

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!