yaml-cpp icon indicating copy to clipboard operation
yaml-cpp copied to clipboard

Replace std::shared_ptr<T>(T*) usage in order to prevent additional memory allocation for shared_ptr control block

Open slavanap opened this issue 9 months ago • 1 comments

slavanap avatar Apr 15 '25 08:04 slavanap

Sure. When the first owner of shared_ptr is created with a constructor from a pointer, it allocates memory for a control block used to reference counting. make_shared method allocates memory for that control block and the object that pointer is stored, with the same allocation - thus 1 extra allocation is eliminated. More precise description is available in the "notes" section here https://en.cppreference.com/w/cpp/memory/shared_ptr/make_shared.html

slavanap avatar Aug 25 '25 09:08 slavanap