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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T03:45:26+00:00 2026-05-26T03:45:26+00:00

Is there a convenient analog of std::bitset<> that’s dynamically sizable at instantiation time, but

  • 0

Is there a convenient analog of std::bitset<> that’s dynamically sizable at instantiation time, but avoids the extra allocation required by boost::dynamic_bitset<>

You can create dynamically sized bit sets easily in C by doing something like :

typedef struct { node_t node; block_t bits[0]; } node_bitset_t;
p = (node_bitset_t *)malloc( (sizeof(node_t) + sizeof(block_t)*blocks) * array_size);

You could do this using std::vector<std::bitset<bits>> only if you know bits at compile time. If you use std::vector<boost::dynamic_bitset<>>, then you’ll see an extra allocator call. Is there a compromise that achieves the above C code’s balance?

You might for-example have some custom allocator for the std::vector<…> that leaves some extra space after each boost::dynamic_bitset<> and allocates m_block there, although that’ll probably still cost you the pointer for m_block.

  • 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-05-26T03:45:26+00:00Added an answer on May 26, 2026 at 3:45 am

    It would be possible to create such a class using placement new, but I’m not aware of a preexisting class which does this. The class wouldn’t be instantiated directly but would be built via a factory; the factory method would use new to allocate the number of bytes necessary, then use placement new to initialize the object at the front of the buffer. The end of the buffer past the size of the class would be the bit storage.

    In practice there’s no need to do this, because it doesn’t save anything vs. dynamic_bitset. With this method you have two parts, a pointer to the bits object and the object itself. With dynamic_bitset you have the dynamic_bitset object which contains the pointer to the bits. Same thing.

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

Sidebar

Related Questions

Is there a convenient way to write a regex that will try to match
is there a convenient way to bypass the private visibility ( edit: that is,
Several Linq.Enumerable functions take an IEqualityComparer<T> . Is there a convenient wrapper class that
Is there a convenient way to calculate percentiles for a sequence or single-dimensional numpy
Is there a convenient way to do this for my extension? I know I
Is there any convenient way to type in braces in Math in Latex? Especially
in languages like PHP or Python there are convenient functions to turn an input
For a machine with multiple NIC cards, is there a convenient method in Java
There is a conversion process that is needed when migrating Visual Studio 2005 web
Is there any convenient way to read and parse data from incoming request. E.g

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.