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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T00:25:17+00:00 2026-06-01T00:25:17+00:00

How can I use std::shared_ptr for array of double? Additionally what are advantages/disadvantages of

  • 0

How can I use std::shared_ptr for array of double? Additionally what are advantages/disadvantages of using shared_ptr.

  • 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-01T00:25:18+00:00Added an answer on June 1, 2026 at 12:25 am

    It depends on what you’re after. If you just want a resizable array of doubles, go with

    std::vector<double>
    

    Example:

    std::vector<double> v;
    v.push_back(23.0);
    std::cout << v[0];
    

    If sharing the ownership of said array matters to you, use e.g.

    std::shared_ptr<std::vector<double>>
    

    Example:

    std::shared_ptr<std::vector<double>> v1(new std::vector<double>);
    v1->push_back(23.0);
    std::shared_ptr<std::vector<double>> v2 = v1;
    v2->push_back(9.0);
    std::cout << (*v1)[1];
    

    Alternatively, Boost has

    boost::shared_array
    

    which serves a similar purpose. See here:

    http://www.boost.org/libs/smart_ptr/shared_array.htm

    As far as a few advantages/disadvantages of shared_ptr go:

    Pros

    • Automated shared resource deallocation based on reference counting – helps avoid memory leaks and other problems associated with things not getting deallocated when they should be
    • Can make it easier to write exception-safe code

    Cons

    • Memory overhead to store the reference count can be significant for small objects
    • Performance can be worse than for raw pointers (but measure this)
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to use the std::shared_ptr in clang++(clang version 3.1 (trunk 143100)) using libstdc++(4.6.1).
I can't use shared_ptr in my project, no boost :( So, I'm having a
I am leaning towards using std::tr1::shared_ptr to automatically manage a pointer to a utility
In C++ you can use std::numeric_limits<FloatingPointType>::digits10 to find out exactly how many places of
Is it safe and correct to use an std::tr1::shared_ptr as in the sample code
I can't think of any situation where std::shared_ptr<Object> obj(new Object(foo, 1)); would be preferred
You can use more than one css class in an HTML tag in current
You can use a standard dot notation or a method call in Objective-C to
I can use properties of an Excel Worksheet to tell if the worksheet is
You can use ftplib for full FTP support in Python. However the preferred way

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.