1

What are the differences between VS2010's std::shared_ptr and boost::shared_ptr?

Are the implementations almost the same? Or are there significant differences?

What is the most efficient/optimized?

Thanks.

4
  • Why not have a look at the source code? Commented Apr 17, 2012 at 9:22
  • 3
    There are differences. How do we know if they are significant for you? Commented Apr 17, 2012 at 9:24
  • 1
    @Nick: In general, Boost and STL C++ source codes are not trivial to read (sometimes they are read-only/write-only code). I'm considering them more like black-boxes. Commented Apr 17, 2012 at 9:42
  • @BoPersson: if there are known differences, it would be interesting to read about them. e.g. Boost's one is better for space efficiency, VS2010's one is better for speed, etc. Commented Apr 17, 2012 at 9:50

1 Answer 1

1

VS2010's shared_ptr is implementation conforming (or, at least, trying to conform) C++11 standard.

boost::shared_ptr on the other hand, was developed way earlier, and as part of boost rather than C++ standard library. I believe both are efficient enough for production use, but using boost forces you to... use boost ;). Which in some cases is quite unacceptable.

Sign up to request clarification or add additional context in comments.

4 Comments

using Boost is not a problem (there are other Boost libraries that can come in handy and are not present in VS2010 std::). And AFAIK it is possible to use Boost in commercial products (correct me if I'm wrong).
FWIW, in VS2008 tr1::shared_ptr implementation was buggy (although it seems that in VS2010 they fixed this particular bug): connect.microsoft.com/VisualStudio/feedback/details/488804/…
It is possible to use it in commercial products, but some companies (i believe even google[citation needed]) have strong code policy against boost and other libraries.
@BartekBanachewicz Yes, you are right, Google does not support all boost collections, but only the ones they have approved. boost:array, boost:ptr_container are allowed at Google. Google Style Guide: google-styleguide.googlecode.com/svn/trunk/cppguide.xml#Boost