getting a giant bitmap into a container

4

440gtx

I would like to represent used/free clusters on a disk drive in a
standard container. Pardon platform specifics, but the cluster data
comes from a POD header followed by the cluster bitmap as defined by
FSCTL_GET_VOLUME_BITMAP. One choice is to create an empty vector
<bool> and manually copy the bits. Since there can be billions of
clusters, this is very inefficient in terms of needing double the
memory and then the time to copy billions of bits:

vector <bool> bitmap;
VOLUME_BITMAP_BUFFER *out = (VOLUME_BITMAP_BUFFER *)malloc(out_len);

…call ioctl…

bitmap.resize(out->BitmapSize.QuadPart);

for (vector <bool>::size_type i = 0; i < bitmap.size(); ++i)
bitmap = (out->Buffer[i/8] >> (i % 8)) & 1;

Are there more appropriate ways?
 
Ö

Öö Tiib

I would like to represent used/free clusters on a disk drive in a
standard container. Pardon platform specifics, but the cluster data
comes from a POD header followed by the cluster bitmap as defined by
FSCTL_GET_VOLUME_BITMAP. One choice is to create an empty vector
<bool> and manually copy the bits. Since there can be billions of
clusters, this is very inefficient in terms of needing double the
memory and then the time to copy billions of bits:

You need double memory each time when you copy something to something
else so if this is concern then do not copy and do not convert. When
unsure then measure.
vector <bool> bitmap;
VOLUME_BITMAP_BUFFER *out   = (VOLUME_BITMAP_BUFFER *)malloc(out_len);

…call ioctl…

bitmap.resize(out->BitmapSize.QuadPart);

for (vector <bool>::size_type i = 0; i < bitmap.size(); ++i)
    bitmap = (out->Buffer[i/8] >> (i % 8)) & 1;

Are there more appropriate ways?


boost::dynamic_bitset or vector of std::bitset are perhaps better
containers for bits than std::vector<bool>.
 
4

440gtx

boost::dynamic_bitset or vector of std::bitset are perhaps
better containers for bits than std::vector<bool>.

Better in what way? Do they solve the performance and memory usage
issue of needing to copy a billion bits one by one from one memory
region to another?
 
Ö

Öö Tiib

Better in what way? Do they solve the performance and memory usage
issue of needing to copy a billion bits one by one from one memory
region to another?

Better since bitset constructor takes at least value (unsigned long)
in, so your copying code does not look like ">(>%)8&":

unsigned char original;
std::bitset<8> copied( original );
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,767
Messages
2,569,572
Members
45,045
Latest member
DRCM

Latest Threads

Top