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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T18:22:39+00:00 2026-05-15T18:22:39+00:00

Does somebody have any idead on how to pass boost::shared_ptr – by value or

  • 0

Does somebody have any idead on how to pass boost::shared_ptr – by value or by reference.

On my platform (32bit) sizeof(shared_ptr) equals 8 bytes and it looks like I should pass them by reference, but maybe somebody has another opinion / did a profile / something like that?

  • 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-15T18:22:40+00:00Added an answer on May 15, 2026 at 6:22 pm

    You can see this in two ways:

    • a boost::shared_ptr is an object (and should be passed by const &).

    • a boost::shared_ptr models a pointer and should be treated as a pointer.

    Both of them are valid, and the second option will incur the cost of constructing and destructing the additional instance (which shouldn’t be a big issue unless you’re writing performance-critical code).

    There are two cases when you should pass by value:

    • when you’re not sure that the type of the pointer will remain the same. That is, if you are considering replacing the shared_ptr<T> with T* in your codebase somewhere in the future, it makes sense to write typedef shared_ptr<T> TPtr; and define your functions as void yourfunction(TPtr value)

      In this case, when you change the pointer type you will only have to modify the typedef line.

    • when you are sharing a pointer between two modules with a different lifetime. In that case, you need to make sure you have two instances of the smart pointer, and that both increment the reference count of the pointer.

    In other cases, it’s a matter of preference (unless you’re writing performance-critical code in which case different rules apply).

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

Sidebar

Related Questions

Does anybody have any experience with TFS no longer letting somebody queue a new
Does somebody know if there is any way to reproduce an ajax suggestion box
Does anyone have ANY ideas what could be causing this. I am on win
Does somebody know what is the memory overhead of a ConcurrentHashMap (compared to a
Does somebody see error here. Whats wrong with this typedef A<B<T>::c> ?? template <const
does somebody tested - will authlogic works with oauth-plugin ( https://github.com/pelle/oauth-plugin ) or not?
Does somebody knows where the file with the actual stored SharedPreferences is located?
Does somebody has an idea?? I've been googling it but didnt found so much
Does somebody know a module, which has a function that returns ( for example
I'm using Ruby on rails. Does somebody know how can I insert a javascript

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.