The Developer Stash

Arbitrary Contemplations
posts - 19, comments - 27, trackbacks - 0

My Links

News




Locations of visitors to this page

 





Elroy D'silva's Blog

Twitter












Archives

Post Categories

Blogs I read

Dynamic bitsets not supported in C++ STL


    It was annoying as well as frustrating to come across the fact that an essential feature was missing in the C++ STL library that I was using. I was writing code that would create a bit array of length ranging from 1 to anything like a thousand or say ten thousand. This needed to be dynamically allocated. So, if I said:

bitset* b;
...
b = new bitset(number_of_bits); // somewhere in the program

    This would create a bitset of "number_of_bits" bits. This would have been cool, but, this isn't the way bitsets are supposed to be used. The usage of bitsets is quite rigid. They are based on templates which need the size of the bit array at compile time which is done something like this.


bitset<1000> b;
or
bitset<1000> *b = new bitset<1000>();

    Now, how does that help me? What if I need more than 1000 bits someday? I can't just give it the highest possible constant value. Everything would fail one day if the question of scalability arises. I don't understand why the folks who developed STL didn't have this in mind. They did it for all the other data structures but, couldn't do the same for bitsets? Why? The question might sound strange but, the answer to this might even be more strange.

    So, what's the solution?

  • Use Boost libraries - which have their implementation of dynamic_bitset. Damn! I can't use Boost as the firm that I work for doesn't want to.
  • Use vector<bool> and implement overload the bitwise operator to act on that. Well, that's as good as creating a new implementation for my own dynamic bitset.

 

    So, I've decided that I'll create my own dynamic version of <bitset> as the guys at MSDN forums told me to.



kick it on DotNetKicks.com

Print | posted on Wednesday, September 03, 2008 11:22 AM | Filed Under [ C++ ]

Feedback

Gravatar

# re: Dynamic bitsets not supported in C++ STL

Boost C++ libraries have dynamic bitsets
10/27/2008 7:44 AM | Zenna
Gravatar

# re: Dynamic bitsets not supported in C++ STL

> I can't use Boost as the firm that I work for doesn't want to.

WTF? Why not? Get a new firm at which to work, if you haven't already.
2/20/2009 7:43 AM | fingerlicker
Post A Comment
Title:
Name:
Email:
Website:
Comment:
Verification:
 
 

Powered by: