I am currently refactoring some old parts of a code. The method I am working on is heavily using the new
and delete
features in order to achieve its purpose. I could easily replace all that with shared pointers for better code clarity and safety. The thing is, that in the end I need to return a pointer to an allocated memory to match the API. This wont work with shared pointers.
I could just allocate a new memory block with new
and copy the contents of the memory allocated by shared_ptr
(my first idea). But then I thought maybe there is a mechanism for telling the shared_ptr
to not to free the allocated memory on context loosing? This way I could return the pointer to the allocated memory by shared ptr without free'ing it.