Search code examples
c++boostbooleandata-storage

What consumes more storage space - boost::dynamic_bitset<> or raw storage?


I have a program storage optimization question.

I have, let say 4096 "knots" stored in a:

  boost::dynamic_bitset<>

I am now considering refactoring my program and build a CKnot class which will contain a bool.

The question is what will consume more space:

  • boost::dynamic_bitset<> ( 4096 , false );
  • CKnot Knot[4096] //contain one bool

Thanks


Solution

  • The bitset will be considerably smaller, as a bool in C++ must be at least a byte in size, whereas each bit in a bitset is exactly that, a bit.