Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8301993
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T17:10:32+00:00 2026-06-08T17:10:32+00:00

Is there some reasonably fast code out there which can help me quickly search

  • 0

Is there some reasonably fast code out there which can help me quickly search a large bitmap (a few megabytes) for runs of contiguous zero or one bits?

By “reasonably fast” I mean something that can take advantage of the machine word size and compare entire words at once, instead of doing bit-by-bit analysis which is horrifically slow (such as one does with vector<bool>).

It’s very useful for e.g. searching the bitmap of a volume for free space (for defragmentation, etc.).

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T17:10:33+00:00Added an answer on June 8, 2026 at 5:10 pm

    Windows has an RTL_BITMAP data structure one can use along with its APIs.

    But I needed the code for this sometime ago, and so I wrote it here (warning, it’s a little ugly):
    https://gist.github.com/3206128

    I have only partially tested it, so it might still have bugs (especially on reverse). But a recent version (only slightly different from this one) seemed to be usable for me, so it’s worth a try.

    The fundamental operation for the entire thing is being able to — quickly — find the length of a run of bits:

    long long GetRunLength(
        const void *const pBitmap, unsigned long long nBitmapBits,
        long long startInclusive, long long endExclusive,
        const bool reverse, /*out*/ bool *pBit);
    

    Everything else should be easy to build upon this, given its versatility.

    I tried to include some SSE code, but it didn’t noticeably improve the performance. However, in general, the code is many times faster than doing bit-by-bit analysis, so I think it might be useful.

    It should be easy to test if you can get a hold of vector<bool>‘s buffer somehow — and if you’re on Visual C++, then there’s a function I included which does that for you. If you find bugs, feel free to let me know.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there some kind of software that I can feed uploaded images to and
Is there some event I can use to tell when the SelectedIndices property changes
Is there some regex that can be passed to re-seq such that it will
Is there a reasonably fast way to extract the exponent and mantissa from a
I am interested in finding out if there exists a program or library which
I assume there is some reasonably straightforward way to add Captcha to a rails3
Is there some reasonably cross platform way to create a thumbnail image given a
Help! I'm writing some code to update a mySQL database using similar to the
Are there some good resources tutorials or anyone has tried to implement a Capcha
Is there some way to define an abstract type as a parameter in an

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.