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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T06:58:16+00:00 2026-05-30T06:58:16+00:00

I am using few library functions that return a pointer created either using malloc

  • 0

I am using few library functions that return a pointer created either using malloc or new.
So, I have my own customer deallocator based on what type of allocation was used.

E.g

shared_ptr<int> ptr1(LibFunctA(), &MallocDeleter); //LibFunctA returns pointer created using malloc
shared_ptr<int> ptr2(LibFunctB(), &newDeleter);  //LibFunctB returns pointer created using new

Now, I understand this is a very naive use of deallocator above but what other scenarios is it heavily used for ?

Also, how can one use a customer allocator ? I tried to assign a custom allocator as below but now how do I actually get it called ? Where does this kind of feature help ?

shared_ptr<int> ptr3(nullptr_t, &CustomDeleter, &CustomAllocator);  //assume both functs are defined somewhere.
  • 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-30T06:58:17+00:00Added an answer on May 30, 2026 at 6:58 am

    I don’t see anything “naive” about using deleters that way. It is the main purpose of the feature after all; to destroy pointer objects that aren’t allocated using the standard C++ methods.

    Allocators are for when you need control of how the shared_ptr‘s control block of memory is allocated and deleted. For example, you might have a pool of memory that you want these things to come from, or if you’re in a memory-limited situation where allocation of memory via new is simply not acceptable. And since the type of the control block is up to shared_ptr, there’s no other way to be able to control how it is allocated except with some kind of allocator.

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

Sidebar

Related Questions

I'm using a library that has quite a few functions that write to a
I have a driver that my company has been using for a few years
I have written a few razor helpers and these helpers use functions that include
I'm using MinGW. I have some code which calls malloc and a few other
I’m using a few custom MSBuild tasks that are checked into source control. I
I have run a few using batch jobs, but, I am wondering what would
Right now I'm using a few scripts to generate files that I'm including as
I have been successfully using my code with the javascript library in the ANTLR
We have a library that provides access to buttons on a device. These buttons
I'm currently using commons-net library for FTP client in my app. I have to

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.