~/talk

C++ Smart Pointers - Usage and Secrets

Talkat NDC TechTown 2019 · 2019-09-02..09-05· [c-and-cpp]
slides:none on file

Compares shared_ptr and unique_ptr with concrete tradeoffs: make_shared saves one allocation and is usually faster but can keep the combined control block alive if weak_ptr observers outlive the resource, creating a logical memory hold; weak_ptr requires lock to get a shared_ptr for thread safety; shared_ptr copying incurs atomic synchronization and measured slowdowns (examples report ~40x to ~80x overhead and CPU stalls up to ~82%); unique_ptr has zero runtime overhead, enforces single ownership at compile time, and should be preferred and passed or stored with moves while shared_ptrs are passed by const reference to avoid needless copies.

AI-written summary · about

  1. 0:00Introduction
  2. 1:10Smart Pointers
  3. 10:27Shared Pointers Details
  4. 12:27Weak Pointers
  5. 18:34MakeShare
  6. 21:56Can we use smart pointers
  7. 25:17Dynamic pointer cast
  8. 27:21Common problem
  9. 28:36How it works
  10. 30:02Performance
  11. 36:51Demonstration
  12. 43:05Measurements
  13. 43:49Unique pointers
  14. 48:34Unique pointers trick
  15. 49:04Unique pointers limitations
  16. 52:34Unique pointers ownership
  17. 55:29Move semantics
~/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.