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?
Sign in to answer questions and track your progress
Sign In