Back to Basics: C++ Smart Pointers
summary
Covers concrete rules: use std::unique_ptr for single ownership (move‑only, noexcept, use release/reset/get), use std::shared_ptr for shared ownership (control block with atomic refcount, copyable, use_count unreliable for races), prefer make_unique/make_shared (one allocation for make_shared), watch double frees when creating separate control blocks from the same raw pointer, use weak_ptr for safe non‑owning references, custom deleters for C APIs (FILE* + fclose), and array support arriving in C++17/C++20 — aims to eliminate leaks.
AI-written summary · about
chapters (17)
- 0:00Smart pointers intro
- 4:17Raw pointers problems
- 7:09Unique pointers ownership
- 11:30Unique pointers internals
- 15:44make_unique cleaner code
- 22:04Shared pointers ownership
- 25:35Shared pointers memory
- 31:13make_shared performance
- 33:21Thread safety shared pointers
- 36:52Unique vs shared pointers
- 37:13Advanced topics
- 37:35Weak pointers safe refs
- 39:42Custom deleters resources
- 43:15Advanced features
- 44:42When smart pointers fail
- 46:27Smart pointer guidelines
- 47:11Summary & Q&A
related talks
50mBack to Basics: Smart Pointers and RAII
11mAnatomy of a Smart Pointer
01h 40mBack to the Basics! Essentials of Modern C++ Style
01h 04mException-Safe Code, Part III
39mBack to Basics: The Rule of Five in C++
58mUnderstanding and Mastering C++'s Complexity
01h 01mException-Safe Code, Part I
58mLeveraging C++20/23 Features for Low Level Interactions
