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

  • Home
  • SEARCH
  • 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 9197693
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T22:07:50+00:00 2026-06-17T22:07:50+00:00

My program will create and delete a lot of objects (from a REST API).

  • 0

My program will create and delete a lot of objects (from a REST API). These objects will be referenced from multiple places. I’d like to have a “memory cache” and manage objects lifetime with reference counting so they can be released when they aren’t used anymore.

All the objects inherit from a base class Ressource.

The Cache is mostly a std::map<_key_, std::shared_ptr<Ressource> >

Then I’m puzzled, how can the Cacheknow when a Ressource ref count is decremented? ie. A call to the std::shared_ptr destructor or operator=.

1/ I don’t want to iterate over the std::map and check each ref.count().

2/ Can I reuse std::shared_ptr and implement a custom hook?

class RessourcePtr : public std::shared_ptr<Ressource>
...

3/ Should I implement my own ref count class? ex. https://stackoverflow.com/a/4910158/1058117

Thanks!

  • 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-06-17T22:07:52+00:00Added an answer on June 17, 2026 at 10:07 pm

    make shared_ptr not use delete shows how you can provide a custom delete function for a shared pointer.

    You could also use intrusive pointers if you wanted have customer functions for reference add and delete.

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

Sidebar

Related Questions

For a school assignment I have to create a C++ program that will create
Is there (somewhere) a command-line program for Windows which will create PNG/JPEG visual from
I am trying to create a program that will get data directly from socket
I am trying to create a program that will be passed input data from
I would like to create a program that will run in background as a
I need to create a program that will download files from FTP Server and
I'm trying to make a program which will create a sum of directories the
I am trying to create a program which will substitute a character in place
I am trying to create a program that will do some simple calculations, but
I want to create an extremely simple iPhone program that will open a telnet

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.