Back to Basics: Smart Pointers
summary
Explains how C++ smart pointers actually work: unique_ptr holds a raw pointer and a deleter (used to wrap C APIs like OpenSSL), shared_ptr stores a separate control block with atomic refcounts and possibly the deleter and pointer-to-delete, and weak_ptr.lock() returns a safe shared_ptr checked for expiry. Recommends make_shared optimization (single allocation), passing smart pointers by value, using enable_shared_from_this (CRTP) when an object must obtain its own shared_ptr.
AI-written summary · about
chapters (14)
- 0:00Introduction to smart pointers
- 1:02Types and basic syntax
- 3:47Unique pointer
- 8:17Custom deleters
- 10:09Implementing custom deleters
- 14:20Smart pointer best practices
- 17:49Shared pointer concepts
- 21:46Shared pointer internals
- 28:22Factory functions
- 33:55Weak pointer functionality
- 37:19Redeeming weak pointers
- 42:58Enable shared from this
- 47:11Networking example
- 52:19Conclusion and Q&A
related talks
01h 02mC++ Smart Pointers - Usage and Secrets
53mSmart Pointers in C++
01h 00mBack to Basics: Pointers
04mSmart Pointers in C++ Are Not Pointers
01h 33mSafe and Sane C++ Types
01h 39m“Leak-Freedom in C++... By Default.”
01h 02mFancy Pointers for Fun and Profit
01h 11mLock-Free Programming (or, Juggling Razor Blades), Part II
