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 74551
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T20:22:33+00:00 2026-05-10T20:22:33+00:00

I am trying to store a large amount of boolean information that is determined

  • 0

I am trying to store a large amount of boolean information that is determined at run-time. I was wondering what the best method might be.

I have currently been trying to allocate the memory using:

pStatus = malloc((<number of data points>/8) + 1);

thinking that this will give me enough bits to work with. I could then reference each boolean value using the pointer in array notation:

pStatus[element]

Unfortunately this does not seem to be working very well. First, I am having difficulty initializing the memory to the integer value 0. Can this be done using memset()? Still, I don’t think that is impacting why I crash when trying to access pStatus[element].

I am also not entirely convinced that this approach is the best one to be using. What I really want is essentially a giant bitmask that reflects the status of the boolean values. Have I missed something?

  • 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. 2026-05-10T20:22:34+00:00Added an answer on May 10, 2026 at 8:22 pm
    pStatus = malloc((<number of data points>/8) + 1); 

    This does allocate enough bytes for your bits. However,

    pStatus[element] 

    This accesses the element’th byte, not bit. So when element is more than one-eighth of the total number of bits, you’re accessing off the end of the array allocated.

    I would define a few helper functions

    int get_bit(int element) {     uint byte_index = element/8;     uint bit_index = element % 8;     uint bit_mask = ( 1 << bit_index);      return ((pStatus[byte_index] & bit_mask) != 0); }  void set_bit (int element) {     uint byte_index = element/8;     uint bit_index = element % 8;     uint bit_mask = ( 1 << bit_index);      pStatus[byte_index] |= bit_mask); }  void clear_bit (int element) {     uint byte_index = element/8;     uint bit_index = element % 8;     uint bit_mask = ( 1 << bit_index);      pStatus[byte_index] &= ~bit_mask; } 

    (error checking on range of element left out for clarity. You could make this macros, too)

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

Sidebar

Related Questions

I have a large core data store that I dont care about encryption. I
I'm trying to figure out the best way to store large binary (more than
I have a stored proc that processes a large amount of data (about 5m
I'm trying to store BitmapData from a MovieClip that is a PNG with transparency.
I have large amount of data to be plotted on iPad using a core
I'm trying to store a very large string which I will ultimately convert to
I am trying to optimize a query that contains a cross join. I have
I'm dealing with a large group of entities that store locations. They are displayed
I am trying to build a data table structure that will best support the
I have a large number of objects I need to store in memory for

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.