c++ - Are new and delete still useful in C++14? -
given availability of make_unique
, make_shared
, automatic deletion unique_ptr
, shared_ptr
destructors, situations (apart supporting legacy code) using new
, delete
in c++14?
while smart pointers preferable raw pointers in many cases, there still lots of use-cases new
/delete
in c++14.
if need write requires in-place construction, example:
- a memory pool
- an allocator
- a tagged variant
- binary messages buffer
you need use placement new
and, possibly, delete
. no way around that.
for containers want write, may want use raw pointers storage.
even standard smart pointers, still need new
if want use custom deleters since make_unique
, make_shared
don't allow that.
Comments
Post a Comment