3 ms·
You actually think managing memory manually using new and delete is easier than dealing with occasional problems with leaking memory using shared_ptr? That seem
by Slyfox33 2y ago
You actually think managing memory manually using new and delete is easier than dealing with occasional problems with leaking memory using shared_ptr? That seems pretty ridiculous to me.
- naertcxx 2y agoFor algorithms like the ones in CLRS, which are explicitly written and proven with pointers in mind, definitely. As I wrote, the stdlib++ agrees. Read that code and reevaluate your view on whether it is ridiculous. For other graphs, it depends on the specific application. I am not saying that shared_ptr is always wrong, but often it is.
- gpderetta 2y agonaertcxx point is that you shouldn't use shared_ptr for your next ptr in your list (or other node based container) node. It is slow and error prone. Instead the list container itself should own the nodes and delete them on container destruction. I think it is a good point. unique_ptr is better, but still not always ideal.