getting a giant bitmap into a container

Discussion in 'C++' started by 440gtx@email.com, Feb 13, 2010.

  1. Guest

    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?
     
    , Feb 13, 2010
    #1
    1. Advertising

  2. Öö Tiib Guest

    On Feb 13, 4:17 am, wrote:
    > 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>.
     
    Öö Tiib, Feb 13, 2010
    #2
    1. Advertising

  3. Guest

    > 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?
     
    , Feb 14, 2010
    #3
  4. Öö Tiib Guest

    On Feb 14, 5:39 am, wrote:
    > > 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?


    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 );
     
    Öö Tiib, Feb 14, 2010
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Roedy Green

    Distrituting Giant Files

    Roedy Green, Jan 6, 2006, in forum: Java
    Replies:
    22
    Views:
    837
    Scott Ellsworth
    Jan 19, 2006
  2. Stephen Tyndall
    Replies:
    12
    Views:
    718
    Gabe Flores
    Jul 24, 2004
  3. Stephen Tyndall

    Giant C++ resources list, 2nd edition

    Stephen Tyndall, Aug 1, 2004, in forum: C++
    Replies:
    9
    Views:
    566
    Walter
    Aug 2, 2004
  4. Gandalf

    Masked bitmap from bitmap

    Gandalf, Jan 29, 2004, in forum: Python
    Replies:
    0
    Views:
    611
    Gandalf
    Jan 29, 2004
  5. xqggz
    Replies:
    1
    Views:
    446
    Victor Bazarov
    Jun 19, 2007
Loading...

Share This Page