Back to Basics: RAII in C++
summary
Claims that RAII, when applied correctly, eliminates leaks, use-after-release and double disposal for most resources and demonstrates this with std::lock_guard, std::unique_ptr and std::jthread examples. Builds a C FILE wrapper using a unique_ptr with custom deleter and a bespoke make_c_file factory, and shows a unique_unlock RAII utility that works. Explains design tradeoffs: default-empty state, copy/move/delete semantics, whether to expose raw handles, and the hard limitation that destructors cannot reliably report release failures.
AI-written summary · about
chapters (20)
- 0:00Introduction to RAII
- 0:33Defining resources
- 1:16Common resource types
- 2:13Resource management issues
- 3:38Manual resource handling
- 6:16RAII concept and ownership
- 7:56Standard RAII examples
- 10:49Storage durations
- 12:04Smart pointers and threads
- 13:50Accessing raw resources
- 15:44Evaluating RAII benefits
- 17:08RAII limitations
- 19:22Implementing custom RAII
- 22:19Factory functions for RAII
- 25:12RAII class design decisions
- 27:55Copy and move semantics
- 30:19Advanced RAII design
- 32:32Custom RAII example
- 34:22Core guidelines and recap
- 35:54Q&A
related talks
50mBack to Basics: Smart Pointers and RAII
01h 01mException-Safe Code, Part I
01h 40mBack to the Basics! Essentials of Modern C++ Style
39mBack to Basics: The Rule of Five in C++
01h 04mException-Safe Code, Part III
35mMistakes to avoid when writing a wrapper around a C library
58mLeveraging C++20/23 Features for Low Level Interactions
40mAdvanced Rust Programming Techniques
