make_shared allocates single block for object and reference counter. So there is an obvious performance benefit using such technique.
I made simple experiment in VS2012 and I was looking for 'evidence':
std::shared_ptr<Test> sp2 = std::make_shared<Test>();
std::shared_ptr<Test> sp(new Test());
// Test is a simple class with int 'm_value' member
when debugging I got in locals view something like this (some lines are deleted)
- sp2 shared_ptr {m_value=0 } [make_shared] std::shared_ptr<Test>
+ _Ptr 0x01208dec {m_value=0 } Test *
+ _Rep 0x01208de0 make_shared std::_Ref_count_base *
- sp shared_ptr {m_value=0 } [default] std::shared_ptr<Test>
+ _Ptr 0x01203c50 {m_value=0 } Test *
+ _Rep 0x01208d90 default std::_Ref_count_base *
It seems that sp2 is allocated in 0x01208de0 (there is a ref counter) and then in 0x01208dec there is an Test object. Locations are very close to each other.
In second version we have 0x01208d90 for ref counter, and 0x01203c50 for object. Those locations are quite distant.
Is this proper output? Do I understand this correctly?