Smart Pointers: Closing Words#
Resource Usage#
How do std::shared_ptr and std::unique_ptr compare?
std::unique_ptrSmall - size of a pointer
Operations compile away entirely
No excuse not to use it
Have to think more though
std::shared_ptrSize of two pointers
Copying manipulates the resource count. Expensive: atomic instructions - memory barriers
Copying manipulates non-adjacent memory locations
Usage is very easy (no
std::moveand such)
Attention
Cyclic references possible!
No garbage collection as in Java
⟶ Leak!!
See below …