Three Allocations

struct Widget { int data[8]; };

auto a = std::shared_ptr<Widget>(new Widget);   // line 1
auto b = std::make_shared<Widget>();            // line 2
auto c = b;                                     // line 3
std::weak_ptr<Widget> w = b;                    // line 4

How many heap allocations do lines 1 and 2 perform between them, and what does line 3 cost?

A

3 allocations; line 3 acquires a mutex on the control block, since shared_ptr is thread safe

B

3 allocations; line 3 allocates nothing and performs an atomic increment of the strong count

C

2 allocations; line 3 allocates a new control block for c

D

4 allocations; line 4 allocates a control block of its own for the weak count