Jump to content
  • Advertisement
Sign in to follow this  
Basiror

STL bitset

This topic is 4809 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 am working on my bitpacking implementation and want to use STL bitset to store the bits I have examined the code of the bitset the data is stored in an array of unsigned long s I have 2 questions 1. Is it guaranteed that there won t be any additional variables in other STL implementations ? So i could simple do a reinterpret_cast on the pointer to send the bitpack over the network. 2. I miss the possibility to set n bits of a int at position idx in the bitset e.g.: for(i=0;i<n;i++) m.set(idx+i,value&(1<<i); is there a similar feature? what i could think of is a second bitset secondset = std::bitset<nbits>(value); firstset |= (secondset << idx); but I would rather prefer the first implementation since my bitsets will be around 150-300 bytes alrge == 2400 bits

Share this post


Link to post
Share on other sites
Advertisement
It would need to store atleast the size and the actual data. Sending it over the network like that is a really bad idea; the bit-data is almost certainly allocated dynamically. All you'll get on the other side is a pointer to who-knows-where.

Share this post


Link to post
Share on other sites
Quote:
Original post by Deyja
It would need to store atleast the size and the actual data. Sending it over the network like that is a really bad idea; the bit-data is almost certainly allocated dynamically. All you'll get on the other side is a pointer to who-knows-where.

I doubt it, at least VC6's implementation doesn't. Remember that bitsets use a fixed size controlled by a template argument.

Even so treating a bitset this way may not be such a great idea, even if they happen to work in most cases. For one it won't be portable to other platforms (you may encounter both bit and byte-order issues) and it's not very efficient when working with multiple bits either (such as the operation you describe).
Consider writing your own alternative bitset instead. It really isn't that hard..

Share this post


Link to post
Share on other sites
I prefer boost::dynamic_bitset if you need bitsets of varying sizes. It has functions allowing you to retrieve blocks of bits out of it as ulong or something. You could pack these into a buffer and send them. If your number of bits is static and you need to send it around like that I might prefer just using a struct with a bitfield inside.

Share this post


Link to post
Share on other sites
i already thought about the bitfield but unfortunatly the data isn t static
i have aready written a little bitset maybe i just refine it a bit

thx

Share this post


Link to post
Share on other sites
Ah, boost's dynamic bitset was what I was thinking of. I've never actually used the standard one. I didn't relieze it was static (Though... well. Duh. ...)

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!