Jump to content
  • Advertisement
Sign in to follow this  
Winograd

Is vectorbool the way to go?

This topic is 4851 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

Hi, I'm currently writing this simple entropy coder (Golomb-Rice to be exact) in C++. Coder outputs variable length codewords and thus I have to code some sort of bitstream solution. I'm going to go with a simple bit container. For this vector<bool> would be great, altough I don't see a really efficient way to serialize it into a true binary bitstream (ie not just ASCII ones and zeros :) ). So my question is, is there a way to extract the bits from vector<bool> in 8 bit blocks (ie unsigned chars) fast? I think this could be possible because of the way vector<bool> stores the bools (ie one bit per bool). Only that I don't see how this could be done with the given interface. If that can't be done, what would you suggest instead? Writing my own container?

Share this post


Link to post
Share on other sites
Advertisement
You might check out boost::dynamic_bitset and see if that meets your requirements. I believe it has the things you are asking for.

Share this post


Link to post
Share on other sites
Thanks, it is almost what I need. It would be perfect for me if it would offer a const iterator for the internal vector<Block> :(

Now I have to copy all the blocks to an external vector before I can write them to a stream. Perhaps this is not a huge performance hit, but still it's completely unnecessary operation. Well, guess I try it out and profile it.

I also looked for the bitmagic lib. Quite a neat little thing, but not a really fit for my needs.

Share this post


Link to post
Share on other sites
vector<bool> has a few quirks to it.
If you're going to be using them you might want to scroll to the bottom of this Guru of the Week article. Apparently vector<bool> is not actually a container (as defined by the standard library's requirements for containers).

Share this post


Link to post
Share on other sites
Yes, I was aware of that, but thanks anyway.

SGI's STL documentation mentions that (sort of). It says that the reference to a bit is: "A proxy class that acts as a reference to a single bit; the reason it exists is to allow expressions like V[0] = true. (A proxy class like this is necessary, because the C++ memory model does not include independent addressing of objects smaller than one byte.)"

So taking the address of the proxy class is not probably something one would like to do and taking the address of one single bit is impossible (on many platforms).

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • 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!