COMS W4995 C++ Deep Dive for C Programmers

Smart Pointers

Lecture outline

sharedptr1.cpp

  1. Introduction to smart pointer

    • Motivation: RAII for any heap-allocated object
    • high-level code overview of create_vec1()
    • auto revisited
  2. SmartPtr<T> implementation

    • Code walk-thru, along with reference counting diagrams
    • Revisit create_vec1(), along with memory layout diagrams
  3. MakeSmartPtr<T> function template

  4. shared_ptr<T> and make_shared<T>()

sharedptr2.cpp

  1. make_shared<T>() combines heap allocations

  2. shared_ptr to an array and custom deleter

  3. Aliasing

  4. weak_ptr

uniqueptr.cpp

  1. unique_ptr