Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

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

I need a way to add arrays containing single bits to a buffer. Has someone any good ideas on how to represent an array of bits and how to represent a buffer for it. The length of an array may change from 1 to 17 bits. I also need to be able to read n bits from a buffer. /Fredrik

Share this post


Link to post
Share on other sites
Advertisement
Thanks Estor!

Looks like I can steal som ideas from that.

This is what I like about the gamedev forum. You can spend hours at google and then there''s always someone in here who can point you to what you really want.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
yeah, use std::vector<bool> (#include <vector> - it contains a specialisation for bools that packs the bits into a char array.

Share this post


Link to post
Share on other sites
quote:
Original post by Fredrik Dahlberg
The STL thing is a template?
If it is, then it would probably be really slow.
Not that it matters for my purpose but anyway.

Gah, that''s BS. They''re just as fast at run-time as regular code. And it''s bitset you want to look into. Really cool class.

Share this post


Link to post
Share on other sites
quote:
Original post by Fredrik Dahlberg
The STL thing is a template?
If it is, then it would probably be really slow.
Not that it matters for my purpose but anyway.
I believe templated code is generated during compile time, so like Zipster said, it''s just as fast as regular code. For example:

template < typename T >
class Blah
{
T test;
};

Blah< int > BlahInt;
// will generate:

// class Blah

// {

// int test;

// };


Blah< MyClass > BlahClass;
// will generate:

// class Blah

// {

// MyClass test;

// };


so it''s like having the compiler to write code for us, we only need to give them the template.

Share this post


Link to post
Share on other sites
I''m not a diehard c++ programmer so I don''t know exactly how templates works. Having a vector of booleans seems like a really bad choice to me. The Bitset class however is exactly what I want, I''ll use that one. Thanks!

Share this post


Link to post
Share on other sites

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