New T (...) vs std :: make_unique <T> (...). release ()
I watched the Hourglass API companion code in CppCon 2014, which is to provide the C API for the C ++ library, mainly by porting class member functions with functions that have a C-signature.
Among other things, I was intrigued by how the object is built. The function hairpoll_construct, which creates a new object hairpoll, the pointer turns
std::make_unique<hairpoll>(person).release()
which is actually called inside a function that handles exceptions. An easier way is to resort to a simple
new hairpoll(person)
What are the scenarios where the former is preferable? Is this related to how this peticuliar API works, or is it more general than that?
If the constructor throws, the expression new¹deallocates memory automatically before passing the exception.
Perhaps the author thought that it was necessary to use a temporary one unique_ptr.
I do not know any advantages.
¹ If the class does not specify a distributor function operator new, without proper dellalokatora functions operator delete. As soon as this was the case with the debug function in the Microsoft MFC class library. Memory leaked, but only in debug builds.