boost dynamic_bitset block size issue

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Seismic
    New Member
    • Mar 2012
    • 2

    boost dynamic_bitset block size issue

    I am designing an application in which I need to deal with many different variables in which different sequences of bits are stored. I have very strict memory requirements so I decided to use the boost::dynamic_ bitset data type which works very well in my scenario as I need to dynamically allocate/deallocate/resize the variables.

    The only problem is that I am not able to change the size of the blocks in which the dynamic_bitsets are stored.

    I mean, even if I specify the blocks should be "unsigned char", I always obtain 32 bytes allocation by sizeof function, even if the variable is empty.

    Is anybody able to help me! This thing is driving me crazy.
  • weaknessforcats
    Recognized Expert Expert
    • Mar 2007
    • 9214

    #2
    You should be able to look at the template to discover how the blocksize is set.

    If it's not to your liking, you should also be able to make a copy of the template (calling it another name and inserting a comment giving credit to boost) and insert your own block allocation.

    Comment

    • Seismic
      New Member
      • Mar 2012
      • 2

      #3
      I got what you said (and thanks in advance for helping me).
      I had a look into the template. The block size is set, by default, to unsigned long (32 bytes). I tried to set the block size to unsigned char (1byte) by using the template syntax (it accepts only unsigned integer data types instead of the default block size) but the output of the function sizeof still is 32 bytes allocation. I was wondering if it is just a matter of "wrong" sizeof output or if the data type actually takes up 32 bytes.

      I try to be clearer. I have to store few bits sequences and allocating 32 bytes for each few bits sequence would be a huge waste of memory. I would prefer allocating 1 or 2 one byte blocks instead.

      As my time for designing the application is running out faster and faster I would avoid to "put my hands" into the boost library.

      Comment

      • weaknessforcats
        Recognized Expert Expert
        • Mar 2007
        • 9214

        #4
        I did this:
        Code:
         bitset<8> set;
          cout << sizeof(set) << endl;
        using the C++ Standard Template and sizeof returns 4 (32 bits) as a default size. I suspect it enlarges in increment of 4. Probably and unsigned int also.

        I suppose if you are really cramped you could use a bitfield.

        Comment

        Working...