
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On Wednesday, May 25, 2011, Phil Bouchard wrote:
So we have shared_ptr being initialized with an object created by operator new. shared_ptr will then allocate another reference counter. 2 allocations is faster than the make_shared counterpart so yes copying a pointer is slower than 2 heap allocations.
What version of boost are you referring to? make_shared used to be slow due to it doing a lot of unnecessary copying of the storage area for the pointee, but that should have been fixed probably a couple years back now. Copying a shared_ptr is fairly slow due to the atomic reference counting, but I would expect a compiler to be able to elide the copy of the make_shared return value. -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.10 (GNU/Linux) iEYEARECAAYFAk3daPAACgkQ5vihyNWuA4VQHQCeM3lG462/Wisv84Iklc5WLtIv 1CwAn1jMJw12gz042FLYChF5L0D88qr+ =bUfW -----END PGP SIGNATURE-----