With the advent of std::unique_ptr damaged std::auto_ptr can be permanently postponed. Therefore, over the past few days, I have been changing my code to use smart pointers and removing all delete from my code.
Although valgrind says my code is clean in memory, the semantic richness of smart pointers will make the code cleaner and cleaner.
In most code, translation is simple: use std::unique_ptr instead of raw pointers held by native objects, throw delete and carefully sprinkle get() , reset() and move() calls, if necessary, interact well with the rest of the code.
I am at the point where I am now translating non-proprietary pointers to smart pointers.
Since I was careful with the lifetimes of my objects (I guarantee that my modules depend in only one direction), valgrind tells me that I have no uninitialized reads, dangling pointers or leaks. So, technically, I could just leave those not owning the source pointers now.
However, one option is to change those that do not own the source pointers to std::shared_ptr , because I know that they are acyclic. Or, would it be better to leave them as source pointers?
I need advice from veteran users of smart pointers regarding what rules you use to decide whether to save non-source pointers as is, or translate them into std::shared_ptr , keeping in mind that I am constantly testing the block and checking my code .
EDIT: Perhaps I am mistaken in using std::shared_ptr - can they be used in combination with std::unique_ptr , or is it so if I use std::shared_ptr , should all descriptors also be std::shared_ptr ?
c ++ memory c ++ 11 smart-pointers
kfmfe04 Dec 01 2018-11-11T00: 00Z
source share