
Explore the RAII idiom with an auto pointer that manages heap memory, preventing leaks as scope ends and its destructor releases resources.
Explore how resource management via raii applies to an auto pointer and a document class with an untitled title, including getters, setters, display, save, and creation with null pointers.
Explore how an auto pointer manages resources like a smart pointer, overloads arrow and dereference operators, and implements bool conversion to behave like a real pointer while avoiding leaks.
Examine safe ownership of an auto pointer by implementing copy constructor and assignment operator to transfer ownership, avoiding shallow copies and destructor crashes.
Examine auto pointer copy semantics, showing ownership transfer and null pointer crashes, reveal subtle production risks, and debate whether copying should be allowed in the copy constructor.
Convert the auto pointer to non-copyable movable resource: implement move constructor and move assignment, ensure noexcept, safely transfer ownership while preventing leaks.
Explore the remaining features of the auto pointer class, including raw-pointer semantics, member access, dereferencing, boolean usage, and default construction, plus ownership transfer, nullptr comparisons, release on demand, and reinitialization.
Add null-pointer comparisons and operator overloads for the auto pointer, enforce explicit conversions and direct initialization, and implement release to transfer ownership and avoid double deletes.
Improve the auto pointer by adding reset functions that delete the underlying pointer, assign null, and support reinitialization with a new resource, and apply noexcept to eligible functions.
Explore how a smart pointer can manage resources acquired in different ways, from fopen-based file reads to loading a DLL and invoking its beep function via Getprocaddress.
Learn how to replace raw pointers with smart pointers, manage dll lifetimes with loadlibrary and free library, and avoid destructor errors and undefined behavior in resource handling.
Implement a Deleter class for the auto pointer, using a default deleter that calls delete and enabling custom deleters to manage files and resources with ownership transfer.
Explore the internal implementation of unique_ptr deleters, using free library or file as the deleter, with function objects and templates, to prevent resource leaks and ensure exception safety.
This lecture shows deleting copy operations to make the auto pointer non-copyable and explains how a deleter increases size due to padding, raising the footprint versus a raw pointer.
Discover how empty base optimization reduces the size impact of an empty deleter by using inheritance instead of composition, enabling a lean unique_ptr internal implementation.
Apply e-bow to the auto pointer class, compare the deleter’s behavior and size with a raw pointer, and introduce a pointer info class for class or pointer deleters via specialization.
explain how tuple enables empty-base optimization (eb0) in unique_ptr internals, replacing the pointer info class, and compare how msvc, gcc, and clang affect object size with different deleter types.
Explore empty base optimization to reduce the Autoptr class memory footprint and assess a tuple-based ebo, noting no unique address in C++20 and MSVC differences.
Explore how to pass an auto pointer into functions using references and const qualifiers, preventing modification of the auto pointer while still allowing changes to the underlying document.
Master parameter handling with auto pointer in a unique_ptr context, implementing new, input, and serialize to write contents to a file, while managing initialization, reset, and ownership transfer.
Explore managing multiple heap-allocated documents with an auto pointer by storing an array and using a custom deleter for delete[]; learn about array specialization and get and subscript access.
Implement a partial specialization of the default deleter for arrays and make the auto pointer work with dynamic arrays, adding a subscript operator and avoiding custom deleters.
Explore a practical make function to initialize auto pointer and dynamic arrays without direct new, using templates, parameter packs, and concepts to disambiguate array types.
Use the make function to ensure the auto pointer is fully constructed before evaluating subexpressions, preventing memory leaks and improving exception safety in c++17.
Explore make auto pointer functions to simplify allocation with value initialization, avoid unnecessary zeroing of uninitialized memory for arrays, and introduce make pointer for overwrite.
Build Your Own unique_ptr: A Hands-On Guide to RAII and Smart Pointers
This is not just a "how to use smart pointers" course — it’s a deep dive into the mechanics and design of modern C++ unique_ptr.
Memory management is one of the most critical — and often misunderstood — aspects of C++. While many developers learn how to use std::unique_ptr, few truly understand how it works under the hood. This course takes you on a step-by-step journey to implement a smart pointer from scratch, teaching you not just how to use modern C++ techniques, but why they matter.
We start with the core philosophy of RAII (Resource Acquisition Is Initialization) and why it is the foundation of safe C++ programming. From there, you’ll write your own AutoPointer class and gradually evolve it into a unique_ptr clone, exploring concepts such as:
RAII and deterministic destruction
Ownership semantics and move-only types
Implementing custom deleters
make-functions (make_unique) and safe resource creation
Empty Base Optimization (EBO) and how the standard library leverages it for efficiency
Practical design trade-offs in real-world C++ libraries
By the end, you'll will gain a deep mastery over the internal mechanics of smart pointers, become fluent in resource-safe C++ techniques, and leave with the ability to design powerful abstractions that blend safety, flexibility, and performance.