Bitarray

Started by
23 comments, last by Fredrik Dahlberg 20 years, 9 months ago
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
Advertisement
Try this:
http://www.programmersheaven.com/zone3/cat481/16565.htm
"The Gods Made Heavy Metal And They Saw That It Was Good They Said To Play It Louder Than Hell We Promised That We WouldWhen Losers Say Its Over With You Know That It's A Lie The Gods Made Heavy Metal And It's Never Gonna Die"THE GODS MADE HEAVY METAL/by ManOwaR
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.
check out STL''s vector< bool > class.
yeah, use std::vector<bool> (#include <vector> - it contains a specialisation for bools that packs the bits into a char array.
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.
Not a problem Fredrik
"The Gods Made Heavy Metal And They Saw That It Was Good They Said To Play It Louder Than Hell We Promised That We WouldWhen Losers Say Its Over With You Know That It's A Lie The Gods Made Heavy Metal And It's Never Gonna Die"THE GODS MADE HEAVY METAL/by ManOwaR
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.
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.
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!

This topic is closed to new replies.

Advertisement