Back to Basics: RAII and the Rule of Zero
summary
Explains why RAII prevents leaks and double-frees using a hand-built NaiveVector that first leaks, then double-deletes, then is fixed with a destructor, copy constructor and copy-and-swap assignment; shows how self-assignment and aliasing break naive code, introduces move semantics and Rule of Zero vs Rule of Three/Five, presents a working swap/ADL pattern, and argues for using std::unique_ptr to delegate ownership and simplify special members.
AI-written summary · about
chapters (36)
- 0:00Introduction to RAII
- 0:53What RAII really means
- 3:08Naïve vector and memory leaks
- 5:43Destructors and cleanup
- 6:52Copy constructor and double frees
- 8:50Initialization vs assignment
- 10:15Rule of Three explained
- 11:48Copy assignment pitfalls
- 13:22Self-assignment and aliasing
- 16:55RAII and exception safety
- 19:35Fixing leaks with destructors
- 20:20Rule of Three and RAIIPtr
- 21:55Explicit default and deleted functions
- 23:12Rule of Zero introduction
- 25:20Rule of Zero explained
- 26:48Resource management classes
- 27:32Rvalue references and move semantics
- 30:19Move constructors and performance
- 31:52Rule of Five explained
- 33:41Copy-and-swap with move semantics
- 36:39By-value assignment operator
- 37:47Rule of Four and a Half
- 38:57Why swap matters
- 41:15Rule of Five vector implementation
- 44:20Manual resource management spots
- 45:54Closer to Rule of Zero with unique_ptr
- 47:02Rule of Five with defaulted members
- 48:13Constructors and Rule of Zero
- 49:22RAII examples overview
- 49:43unique_ptr resource management
- 51:09shared_ptr and reference counts
- 52:22unique_lock and mutex locks
- 53:08ifstream and file handles
- 54:45Move operations and empty states
- 55:32RAII without copy or move
- 55:56Q&A session
related talks
01h 33mSafe and Sane C++ Types
01h 02mBack to Basics: Exceptions
01h 04m“Sane and Safe C++ Classes”
39mTemporal Dynamics - Exploring the Intricacies of Object Lifetimes in Modern C++
54mWriting C++ to Be Read
01h 23mThis is C++ - How to Use the C++ Superpower to Write Better C++ Code
01h 01mEasy to Use, Hard to Misuse: Declarative Style in C++
01h 11mI just wanted to point to something!
