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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T02:14:41+00:00 2026-05-18T02:14:41+00:00

I am using boost shared_ptr with my own memory manager like this (stripped down

  • 0

I am using boost shared_ptr with my own memory manager like this (stripped down example, I hope there are no errors in it):

class MemoryManager
{
public:
    /** Allocate some memory.*/
    inline void* allocate(size_t nbytes)
    {
        return malloc(nbytes);
    }
    /** Remove memory agian.*/
    inline void deallocate(void* p)
    {
        free(p);
    }


};

MemoryManager globalMM;

// New operators
inline void* operator new(size_t nbytes, ogl2d::MemoryManagerImpl& mm)
{
    return globalMM.allocate(nbytes);
}

// Corresponding delete operators
inline void operator delete(void *p, ogl2d::MemoryManagerImpl& mm)
{
    globalMM.deallocate(p);
}

/** Class for smart pointers, to ensure
     *  correct deletion by the memory manger.*/
class Deleter
{
public:
    void operator()(void *p) {
    globalMM.deallocate(p);
}
};

And I am using it like this:

shared_ptr<Object>(new(globalMM) Object, Deleter);

But now I am realizing. If the shared_ptr deletes my onject, it calls Deleter::operator() and the objects gets deleted. But the destructor does not get called …

How can I change this?

  • 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-18T02:14:42+00:00Added an answer on May 18, 2026 at 2:14 am

    Because deleter should destroy the object:

    class Deleter
    {
    public:
       void operator()(Object *p) {
        p->~Object();
        globalMM.deallocate(p); 
       }
    };
    

    Edit: I was wrong in my deleter, fixed

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

Sidebar

Related Questions

Is the following code thread safe when using boost shared_ptr. Thanks! class CResource {
I have a C++ RAII class for managing Win32 HANDLEs using boost::shared_ptr<> that looks
Suppose I have class like class A{ public: A(int a, boost::shared_ptr<int> ptr){ // whatever!
When using the pImpl idiom is it preferable to use a boost:shared_ptr instead of
How much do using smart pointers, particularly boost::shared_ptr cost more compared to bare pointers
Since I have started using this site, I keep hearing about the Boost library.
I'm using Boost/shared_ptr pointers throughout my application. When the last reference to an object
We've pretty much moved over to using boost::shared_ptr in all of our code, however
In my current project I am using boost::shared_ptr quite extensively. Recently my fellow team
If I have a class with a private construction, using boost::make_shared() to construct a

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.