   Bitmasks for flags
  I''m going to have a lot of flags for a particular process I am doing, they need to be stored, read and altered during this process.  As there might be a lot of flags I was thinking of using an unsigned char or something and using the bits as flags instead to save memory (important for this process!).However, I heard its very slow.  Is it really that bad?The process needs to be as fast as possible, yet memory requirements to a minimum - to the point where I am considering using bits not bools. 
  Correct me if I''m wrong but a binary and shouldn''t be that slow. Binary And and "!= 0"  is all you need to use to read the flag from from the variable.  ;  bitwise opearations are as fast as they can be...the only trouble is the quantity... char will give u 8 flags, int 32, long long 64... enough? ;  Search for "partial register stall". A quick explanation: 8 bit registers are parts of the 32 bit regs on IA-32; changes to one are ''merged'' into the whole register. This means read-after-write and write-after-write dependencies for the different parts of a 32 bit reg! That''s not so good on Athlons, and devastating for P4s.For this reason, compilers usually load 8 bit variables into the full 32 bit register (movsx, movzx for unsigned), and work with those.But how do you expect someone to help you without specifics? What CPU? How many bits to be stored? How many pieces of data total? What for? ;  I didn''t realise the CPU counted as much as it did.I''m looking at around 4-6 flags (bits) required, so I was looking at using 1 byte (an unsigned char for example).  They will be used as flags in a CSG based process, so lots of flags to say whether faces have been processed, whether a face is inside or outside etc.  And these flags have to be altered a lot of times. ;  Yes for a 32-bit CPU, always try to use a DWORD even when you only need a byte. A speed test of anything you want will take only a few mins to set up so give it a try... bits vs flags, bytes vs long words.MarkCornutopia Gameshttp://www.cornutopia.netSound Effects For Game Developershttp://www.indiesfx.co.uk;  hmm, the altering often part is the problem. You''ll have to try both ways, and see what the compiler does with them (check asm output).I would think your memory requirement forces the issue: either 4x the space required is acceptable, or it isn''t, and you have to live with (possibly) slower access.Mark: overgeneralization  It''s not all that bad.But wait, there''s another way: can you combine say 8 fields into one dword, assuming only 4 flags are needed? That''d be better than both alternatives except on P4s, which are crippled by the lack of a real shifter (grrr). ;  Thanks for the info everyone.  I''ll run some tests, and see how things turn out. ;  One thing that''s always really bugged me about using bitsets to store flags is that it''s a pain to figure out which flags are set from the value of the DWORD.  I mean, you have to read the values in hex, and with my flags like :enum CSGFlags {CSG_Proccessed = 1,CSG_Inside = 2,CSG_Rendered = 4,...};So, in order to not have to reference back into the CSGFlags all the time, i usually end up typing (o.csgFlags & CSG_Processed) into a debug watch window, which is a big pain.Anyone know any clever tricks facilitating debugging bit flags in msvc? ;  hmm, stupid idea: make or cast it to an enum type, which also includes values for combinations of flags.enum { A = 1, B = 2, AB = 3 } 