C++ Smart Pointers - Usage and Secrets
summary
Compares shared_ptr and unique_ptr with concrete tradeoffs: make_shared saves one allocation and is usually faster but can keep the combined control block alive if weak_ptr observers outlive the resource, creating a logical memory hold; weak_ptr requires lock to get a shared_ptr for thread safety; shared_ptr copying incurs atomic synchronization and measured slowdowns (examples report ~40x to ~80x overhead and CPU stalls up to ~82%); unique_ptr has zero runtime overhead, enforces single ownership at compile time, and should be preferred and passed or stored with moves while shared_ptrs are passed by const reference to avoid needless copies.
AI-written summary · about
chapters (17)
- 0:00Introduction
- 1:10Smart Pointers
- 10:27Shared Pointers Details
- 12:27Weak Pointers
- 18:34MakeShare
- 21:56Can we use smart pointers
- 25:17Dynamic pointer cast
- 27:21Common problem
- 28:36How it works
- 30:02Performance
- 36:51Demonstration
- 43:05Measurements
- 43:49Unique pointers
- 48:34Unique pointers trick
- 49:04Unique pointers limitations
- 52:34Unique pointers ownership
- 55:29Move semantics








