I\'m interested if these two lines of code are the same:
shared_ptr sp(new int(1)); // double allocation?
shared_ptr sp(make_shared<
Explanation from cppreference std::shared_ptr in Implementation notes section
In a typical implementation, std::shared_ptr holds only two pointers:
- a pointer to the managed object
- a pointer to control block
When shared_ptr is created by calling std::make_shared or std::allocate_shared, the memory for both the control block and the managed object is created with a single allocation. The managed object is constructed in-place in a data member of the control block. When shared_ptr is created via one of the shared_ptr constructors, the managed object and the control block must be allocated separately. In this case, the control block stores a pointer to the managed object.