Skip to content
Module 3

Memory & Resources

Master C++'s ownership model — from raw pointers through smart pointers and move semantics — to write code that never leaks.

Pointers & References

  1. Pointers: Addresses, Dereferencing & Arithmetic

    Understand pointers as memory addresses, learn address-of and dereference operators, pointer arithmetic within arrays, const correctness with pointers, and when raw pointers are still appropriate in modern C++.

  2. References: Lvalue, Rvalue & Pitfalls

    Explore lvalue and rvalue references, understand C++ value categories, learn reference collapsing rules and forwarding references, and avoid dangling reference bugs.

  3. Dynamic Memory: new, delete & Their Dangers

    Learn how dynamic allocation works with new and delete, understand the dangers of memory leaks, double-free, and use-after-free, and discover why modern C++ should contain zero raw new/delete.

Smart Pointers

  1. std::unique_ptr: Exclusive Ownership

    Learn how std::unique_ptr provides zero-overhead exclusive ownership, how to use make_unique, custom deleters for C resources, and factory function patterns.

  2. shared_ptr, weak_ptr & Ownership Graphs

    Understand reference-counted shared ownership with shared_ptr, break cycles with weak_ptr, learn about control blocks and aliasing, and know when shared_ptr is the wrong choice.

Move Semantics & RAII

  1. Move Semantics & std::move

    Understand the problem move semantics solves, how std::move is a cast (not a move), implement move constructors and move assignment, and learn why noexcept is critical for container performance.

  2. Perfect Forwarding & std::forward

    Understand why named rvalue references are lvalues, learn the canonical forwarding pattern with std::forward, and see how emplace_back uses variadic forwarding to construct objects in-place.

  3. RAII: The Fundamental Resource Pattern

    Learn RAII (Resource Acquisition Is Initialization) — the core C++ pattern for exception-safe resource management. Implement RAII wrappers, understand lock_guard and scoped_lock, and learn why RAII types must be move-only or ref-counted.

Advanced Memory

  1. Memory Layout, Alignment & Object Representation

    Understand struct padding and alignment requirements, optimize member ordering for size, learn about cache lines and false sharing, and use C++20 features like [[no_unique_address]] for compact layouts.