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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T17:00:54+00:00 2026-05-30T17:00:54+00:00

In a project, I have two kinds of classes: Type A: normally allocated classes

  • 0

In a project, I have two kinds of classes:

  • Type A: normally allocated classes that I manage with std::unique_ptr<>
  • Type B: classes whose new has been overridden to allocate memory from boost memory pool

For the latter, the proper usage is to call new, like usual, to allocate a new instance, but to never call delete. These objects get cleaned up when the memory pool object goes out of scope.

Therefore, if I accidentally store a Type B instance in an std::unique_ptr<>, I will get a segmentation fault. Likewise, calling delete explicitly on a Type B pointer would be be a bad idea.

What kinds of C++ mechanisms should I use to prevent these types of errors from occurring?

As a simple, but ugly fix, I’m thinking of renaming all my Type B classes to have a prefix like MP (for memory pool), so I visually know not to stuff them inside a std::unique_ptr<>.

However, it would be highly preferable to have a language mechanism which can catch problems during compilation, or at least die in a more obvious way should I or other members of my team accidentally make these types of mistakes.

  • 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-30T17:00:55+00:00Added an answer on May 30, 2026 at 5:00 pm

    Well, I see in boost memory pool, there is one function called is_from() which tells if a given memory is from the pool or not. Having said that, you can override delete operator, where you can check if the memory is from the boost memory pool, means delete it only if it is not from the pool. You can also use custom deleter for std::unique_ptr if it in some way helps you.

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

Sidebar

Related Questions

I have two projects, the DLL project which has all my logic and data
I have two projects: A/B. Project A is the project that contains all of
I have two different kinds of objects that I'd like to live under the
I'm developing a project where I have an entity which may have two kinds
I'm developing a project where I have an entity which may have two kinds
Suppose my solution have two project: myApp: silverlight application project: the default application App
I have a Project Collection setup in my TFS2010RC deployment. I have two Projects
I have two tables: entitytype and project . Here are the create table statements:
I have two applications in my project 'test' the applications are one.mxml and two.mxml
I have two libraries and a single application assembly project layout and I'm wondering

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.