473,408 Members | 1,738 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,408 software developers and data experts.

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.
Mar 12 '12 #1

✓ answered by weaknessforcats

I did this:
Expand|Select|Wrap|Line Numbers
  1.  bitset<8> set;
  2.   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.

3 3201
weaknessforcats
9,208 Expert Mod 8TB
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.
Mar 12 '12 #2
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.
Mar 12 '12 #3
weaknessforcats
9,208 Expert Mod 8TB
I did this:
Expand|Select|Wrap|Line Numbers
  1.  bitset<8> set;
  2.   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.
Mar 13 '12 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Sam Smith | last post by:
I've just started to play around with boost in general and the dynamic_bitset in particular. I want to use the dynamic_bitset to hold an array of data as stream of bits: unsigned char data =...
1
by: Saleh, Amgad H | last post by:
The default block size which represents the page size is 8192 defined in pg_config.h.in. I've been trying to increase that to 16384 and rebuild postgreSQL. I was able to build it and it showed...
1
by: Eliyahu Goldin | last post by:
When I run my ASP.NET application first time after deployment, it runs OK. On the second run, when one of my web forms tries to read session variables set in another form, it finds them empty....
6
by: dee | last post by:
Here is a a list of my hyperlinks in my home page: <A class="theclass" href="Default.aspx">Home</A> <A class="theclass" href="Search.aspx">Search</A> <A class="theclass"...
6
by: Gian | last post by:
Hi, I'm trying to use DIV instead of tables for positioning objects on the page. It was great till I realized that IE sizes DIVs differently from Firefox. Please see example at:...
1
by: ppuniversal | last post by:
Hello, I am making a DES encryption/decryption program using OpenSSL library. I am using function des_ecb_encrypt(des_cblock *input, des_cblock *output, des_cblock *keysched, int mode); ...
1
by: Simon Gare | last post by:
Hi, I cant seem to alter the text size on the code below only the colour, the code you see is all that the page consists of from start to finish that's all of it, cant apply css nothing works. ...
1
by: Mike | last post by:
I am using PowerShell to download an XML file into a string using the DownloadString(URI) method of System.Net.WebClient object. Sample commands below: $Result = $Null; $WebClient = new-object...
2
by: Codeseeker99 | last post by:
my code works for SIZE 4, but I was trying to get my code to Re-Size in SIZE 3, SIZE 7. If you can look at my "for (int" and let me know what I need to change to get it to work in all three sizes. ...
0
by: devil81 | last post by:
Hi: I would be extremely grateful if you could help me with what is quickly becoming a rather annoying code issue. I have coded a recursive emulation of ls -l and am completely stuck on coding...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.