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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T14:37:01+00:00 2026-05-17T14:37:01+00:00

I have a C++ application which makes extensively use of pointers to maintain quite

  • 0

I have a C++ application which makes extensively use of pointers to maintain quite complex data structures. The application performs mathematical simulations on huge data sets (which could take several GB of memory), and is compiled using Microsoft’s Visual Studio 2010.

I am now reworking an important part of the application. To reduce errors (dangling pointers, memory leaks, …) I would want to start using smart pointers. Sacrificing memory or performance is acceptible as long as it is limited.

In practice most of the classes are maintained in big pools (one pool per class) and although the classes can refer to each other, you could consider the pool as owner of all the instances of that class. However, if the pool decides to delete an instance, I don’t want any of the other classes that still refers to the deleted instance to have a dangling pointer.

In another part I keep a collection of pointers to instances that are delivered by other modules in the application. In practice the other modules maintain ownership of the passed instance, but in some cases, modules don’t want to take care of the ownership and just want to pass the instance to the collection, telling it “it’s yours now, manage it”.

What is the best way to start introducing smart pointers? Just replacing pointers [at random] with smart pointers doesn’t seem a correct way, and probably doesn’t deliver all the (or any of the) advantages of smart pointers. But what is a better method?

Which types of smart pointers should I further investigate? I sometimes use std::auto_ptr for the deallocation of locally allocated memory, but this seems to be deprected in C++0x. Is std::unique_ptr a better alternative? Or should I go straight to shared pointers or other types of smart pointers?

The question Replacing existing raw pointers with smart pointers seems similar but instead of asking how easy it is, I am asking what the best approach would be, and which kind of smart pointers are suited best.

Thanks in advance for your ideas and suggestions.

  • 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-17T14:37:02+00:00Added an answer on May 17, 2026 at 2:37 pm

    Here are the 3 varieties found in the new C++11 standard (unique_ptr replaces auto_ptr)

    http://www.stroustrup.com/C++11FAQ.html#std-unique_ptr

    http://www.stroustrup.com/C++11FAQ.html#std-shared_ptr

    http://www.stroustrup.com/C++11FAQ.html#std-weak_ptr

    You can read the text for each pointer and there is an explanation of when to use which in there. For local memory management unique_ptr is the choice. It is non-copyable but movable so as you move it around the receiver takes ownership of it.

    Shared_ptr is used if you want to share an object instance around with no one really owning the object and to make sure it doesn’t get deleted while someone still has a reference to it. Once the last user of an object destroys the shared_ptr container, the contained object will be deleted.

    weak_ptr is used in conjunction with shared_ptr. It enables one to “lock” to see if the reference shared_ptr object still exists before trying to access the internal object.

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

Sidebar

Related Questions

I have developed a C# application which makes heavy use of events. Now this
I have a Web Application which at various points makes users enter dates and
We have an ASP.NET web application which uses ASP.NET Ajax. We open it from
We have a GWT application which draws some resources from a separate servlet via
We have a chat application which works on ASP.Net web applications. We want to
I have created one application which is reading outlook mail, but when user install
I need to make an application which dynamically generates some number of forms and
In the vertex shader program of a WebGL application, I am doing the following:
I'm developing an application for transferring databases and directories of user-uploaded images/documents from our
I am working on a fairly large MVC 3 application, and I'm running into

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.