Jump to content
  • Advertisement
Sign in to follow this  
stu2000

Create bitset subset of larger bitset.

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

Anyone know how to optimize this code much better?
std::bitset<320> bitset1;
//bunch of code here that alters bitset 1 values


//create a subset of bitset 1
std::bitset<240> bitset2;
for(unsigned int s=0; s < 240; s++)
{
bitset2[s] = bitset1[s];
}


The values 320 and 240 are not specific, just used as an example. Seems a horrible waste of cpu to loop through a bitset 240 times to copy a section of it. Unfortunately if you try and cast it with td::bitset<240> bitset2(bitset1); that doesn't compile.

Thanks in advance.
Stu

Share this post


Link to post
Share on other sites
Advertisement
As far as I can tell you have three options here.

1. Hope the compiler doesn't generate code that is too slow for that loop in release. It's possible that unrolling it manually 8 times would help there, but I suspect that still wouldn't make it anywhere near as fast as the obvious memcpy() implementation.

2. Make all your bitsets the same size.

3. Implement your own bitset template, with a fast copying function.

Share this post


Link to post
Share on other sites
Thanks, yah I think I am going to have to write own bitset template in order to make them dynamic sizeable.

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!