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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T12:50:44+00:00 2026-06-08T12:50:44+00:00

my understanding of the new memory <memory> header in C++11 is a bit week,

  • 0

my understanding of the new memory <memory>header in C++11 is a bit week, but from what I can tell shared_ptr is refcounted ptr that makes it really really expensive to copy it(esp on for example ARM arch). And unique_ptr is pretty much the very very light wrapper around new/delete. And it is movable, so it is not like are limited by the scope where you created it.
So my question is:
is there a singlethreaded code usage where shared_ptr is prefered to unique_ptr?

Im not interested in answers like: making your singlethreaded code ready for future multithreading. Presume code is and will stay singlthreaded.

  • 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-08T12:50:46+00:00Added an answer on June 8, 2026 at 12:50 pm

    Your dwelling on threading here is kind of a red herring; there’s a clear contrast between the two, and it has little to nothing to do with threads. If you’re using these classes in a single-threaded environment, you may be able to turn off the atomic operations support; for example, with Boost, define the macro BOOST_SP_DISABLE_THREADS.

    You use shared_ptr<> when you’re not quite sure what the lifetime of an object will be, and want “the last guy in the room to shut off the lights” — i.e., you don’t want the object to be deleted until no client is using it any longer. You use unique_ptr<> when you know exactly who is going to delete the object — i.e., when the lifetime of the pointed-to object is precisely delimitated by a scope.

    It is true that copying a shared_ptr<> is not free, but it’s far from “really, really expensive.” You pay a little bit for the reference counting overhead, but that’s the whole point of using it: you need to keep track of the clients of the object; there’s a little cost involved, but you get the benefit of not leaking the object.

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

Sidebar

Related Questions

Continuing the discussion from Understanding VS2010 C# parallel profiling results but more to the
I'm new to Objective-C and I am having some difficulty with understanding memory management.
I need some help understanding how 32 bit applications use memory on a 64
I know that the new keyword is calling the class constructor but at which
I am still fairly new to understanding android and heard about activity stacks. From
From this reference: When a new object is created, memory for it is allocated,
I am new to vba and I have problem understanding the workbooks in vba
I'm quite new to this (understanding the WP Guts), and I wanted to understand
I am new to programming and am having difficulty with understanding object lifetime /
i'm new to c++ and having a little problem understanding about c++'s casting. According

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.