~/talk

Back to Basics: RAII and the Rule of Zero

Talkat CppCon 2019 · 2019-09-15..09-20· [software-architecture]
slides:none on file

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

  1. 0:00Introduction to RAII
  2. 0:53What RAII really means
  3. 3:08Naïve vector and memory leaks
  4. 5:43Destructors and cleanup
  5. 6:52Copy constructor and double frees
  6. 8:50Initialization vs assignment
  7. 10:15Rule of Three explained
  8. 11:48Copy assignment pitfalls
  9. 13:22Self-assignment and aliasing
  10. 16:55RAII and exception safety
  11. 19:35Fixing leaks with destructors
  12. 20:20Rule of Three and RAIIPtr
  13. 21:55Explicit default and deleted functions
  14. 23:12Rule of Zero introduction
  15. 25:20Rule of Zero explained
  16. 26:48Resource management classes
  17. 27:32Rvalue references and move semantics
  18. 30:19Move constructors and performance
  19. 31:52Rule of Five explained
  20. 33:41Copy-and-swap with move semantics
  21. 36:39By-value assignment operator
  22. 37:47Rule of Four and a Half
  23. 38:57Why swap matters
  24. 41:15Rule of Five vector implementation
  25. 44:20Manual resource management spots
  26. 45:54Closer to Rule of Zero with unique_ptr
  27. 47:02Rule of Five with defaulted members
  28. 48:13Constructors and Rule of Zero
  29. 49:22RAII examples overview
  30. 49:43unique_ptr resource management
  31. 51:09shared_ptr and reference counts
  32. 52:22unique_lock and mutex locks
  33. 53:08ifstream and file handles
  34. 54:45Move operations and empty states
  35. 55:32RAII without copy or move
  36. 55:56Q&A session
~/search
type to search 6,249 conferences, 138,987 speakers and 185,172 talks
~/help
cmdctrl k
search every conference, speaker and series
/
focus the filter search
h
home
c
conferences
s
speakers
e
series
t
light / dark — the status bar button does the same
?
this help
esc
close this, then clear every filter — or just the search, while you are typing in it

Ignored while you are typing. Pages without a filter rail have no search to focus.