Bitarray

Started by
23 comments, last by Fredrik Dahlberg 20 years, 9 months ago
quote:Original post by Zipster
bitset still uses bool, only it''s specifically designed for bit operations. Although the exact implementation should be of no consequence since it''s guaranteed that the objects stored will behave like bits.

[edited by - Zipster on July 5, 2003 3:47:45 PM]


At least in vc++ .net, bitset stores bits as bits, and not as booleans. However, they are stored in groups of 4 bytes (the size of a long), so a bitset of, for example, 2 bits will unfortunately take up 4 bytes. Though, a bitset of 100 bits will only take up 16 bytes.
Advertisement
quote:Original post by Zipster
quote:Original post by Jenison
Not true at all ... we ran some performance tests against MS STL vs Dinkumware STL vs straight out our array handler ... guess which is the slowest ... MS. Actaully ... MS is a slice of Dinkumware. The lastest version of Dinkum has come a long way since MS stole their version.

Fastest was our array handler...STL adds overhead that you just dont need when it comes to performance.

While I dont deny its ease ... its a great lib and I use it myself. But when I care about saving every last MS ... I dont use STL

But are you arguing that was due to the usage of templates, or different STL versions? I was saying that templates don''t inherently create slower code.


your statement is correct ... templates dont ...

I think I need to clear out the misunderstanding about my first statement. I didn''t think it was going to be slow just becuse it was a template. I thought it was going to be slow and steal alot of memory cause the template is obviously not meant to be used for bitmanipulation.
It has been said a hundred times, and I will repeat it.

std::vector<bool> is a specialization of the general std::vector template. Meaning, std::vector<bool> has an implementation that differs from the general template.

It will use bools in its _interface_ but store those booleans in single bits. Thus, std::vector<bool> will do what is expected, and be efficient. std::vector<BOOL> (which would be the same as std::vector<int> will _not_ be efficient memory usage.
i''m feeling very generous today

CBitset.h

.Resize
Pass the amount of bits you want to use and it''ll resize the array accordingly (deletes current contents if any)

.On
returns bit''s current value (1 or 0)

.Off
returns !On. I only added it to make my code look a little prettier.

.Set
turns on the desired bit

.Clear
turns off the desired bit

.Reset
turns off all the bits

.Delete
deletes the array of bits

This topic is closed to new replies.

Advertisement