Which is the best way for holding flags?

From: loquak (liam_parc_at_hotmail.com)
Date: 11/30/04


Date: Tue, 30 Nov 2004 03:33:05 +0200

Greets.
I wonder which way would be the best for holding some state flags in terms
of memory use and efficiency.

a)

struct FLAGS
{
bool flag1 : 1;
bool flag2 : 1;
bool flag3 : 1;
...
}
FLAGS flags;

b)

enum FLAGS
{
flag1,
flag2,
flag3
...
}
std::bitset<FLAGS> flags;

c)

bool flag1;
bool flag2;
bool flag3;
...

Which way would you prefer?



Relevant Pages

  • Re: [RFC][PATCH] A generic boolean
    ... -C++ and Java fans will treat bool as a green light to the following ... if (!(flags == false)) ... accept stupid bool logic code". ...
    (Linux-Kernel)
  • [PATCH 2/5] ring-buffer: remove unused variable
    ... [Impact: fix compiler warning] ... bool lock_taken = false; ... unsigned long flags; ... Please read the FAQ at http://www.tux.org/lkml/ ...
    (Linux-Kernel)
  • Re: Which is the best way for holding flags?
    ... > I wonder which way would be the best for holding some state flags in terms ... memory use and efficiency are 2 very different things. ... It is undoubtedly faster to read and write bool or perhaps char values ...
    (comp.lang.cpp)
  • CListBox resize
    ... BOOL CTestListBox::PreCreateWindow (CREATESTRUCT& cs) ... when user press key on a view. ... What flags do I need to set? ...
    (microsoft.public.vc.mfc)