Smart Pointers: Closing Words¶
Resource Usage¶
How do std::shared_ptr
and std::unique_ptr
compare?
std::unique_ptr
Small - size of a pointer
Operations compile away entirely
No excuse not to use it
Have to think more though
std::shared_ptr
Size 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::move
and such)
Attention
Cyclic references possible!
No garbage collection as in Java
⟶ Leak!!
See below …