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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T05:47:22+00:00 2026-06-12T05:47:22+00:00

If we assume that std::shared_ptr stores a reference count (which I realize the standard

  • 0

If we assume that std::shared_ptr stores a reference count (which I realize the standard does not require, but I am unaware of any implementations that don’t), that reference count has a limited number of bits, and that means there is a maximum number of references that are supported. That leads to two questions:

  • What is this maximum value?
  • What happens if you try to exceed it (e.g., by copying a std::shared_ptr that refers to an object with the maximum reference count)? Note that std::shared_ptr‘s copy constructor is declared noexcept.

Does the standard shed any light on either of these questions? How about common implementations, e.g., gcc, MSVC, Boost?

  • 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-12T05:47:23+00:00Added an answer on June 12, 2026 at 5:47 am

    We can get some information from the shared_ptr::use_count() function. §20.7.2.2.5 says:

    long use_count() const noexcept;
    

    Returns: the number of shared_ptr objects, *this included, that share
    ownership with *this, or 0 when *this is empty.

    [Note: use_count() is not necessarily efficient.—end note ]

    At first sight the long return type seems to answer the first question. However the note seems to imply that shared_ptr is free to use any type of reference counting it wants to, including things like a list of references. If this were the case then theoretically there would be no maximum reference count (although there would certainly be a practical limit).

    There is no other reference to limits on the number of references to the same object that I could find.

    It’s interesting to note that use_count is documented to both not throw and (obviously) to report the count correctly; unless the implementation does use a long member for the count I don’t see how both of these can be theoretically guaranteed at all times.

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

Sidebar

Related Questions

Let's assume that we need some class for wrapping std::string, and besides all other
std::map<int,int> mapy; ++mapy[5]; Is it safe to assume that mapy[5] will always be 1?
Assume that we have two sets: A=(a_1,a_2,...,a_m) and B=(b_1,b_2,...,a_n) (Not necessarily of same size).
Assume that we have a large file which can be read in chunks of
Assume that I have a var std::string sourceCode; where I have loaded a cpp
I assume that abs and fabs are behaving different when using math.h . But
I'm just getting used to smart pointers using std::auto_ptr. Assume that I want to
I am trying to understand which implementation below is faster. Assume that one compiles
Can I assume that for any type T , the type std::list<T> will have
Hi assume that I have class A : using namespace std; template <class T>

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.