Pointers and manual memory

This part of the C++ course goes under the containers, to the pointer and the memory it addresses. Address-of and dereference come first, then arithmetic over an array and its one-past-the-end rule, then new and delete and the leak they leave. A vector-like class is rebuilt with a move constructor, and the two smart pointers, a custom deleter and a placement new show what the standard library does with the same bytes. The part ends on alignment, the lifetime of an object and an allocator.

8.1 Pointers address-of, dereference, nullptr, a pointer as a parameter and the difference from a reference Open 8.2 Pointer arithmetic walk an array, one past the end, the distance between pointers and the bug that reads past it Open 8.3 new and delete heap allocation, delete and delete[], a leak, a double delete and why the standard library owns memory Open 8.4 A vector-like class allocate, grow, copy, release, and the same class rebuilt with a move constructor Open 8.5 std::unique_ptr exclusive ownership, make_unique, move-only semantics and a factory that returns one Open 8.6 std::shared_ptr and std::weak_ptr a reference count, make_shared, a cycle that leaks and weak_ptr that breaks it Open 8.7 Custom deleters close a FILE, wrap a C handle, a deleter as a function object and unique_ptr with a lambda Open 8.8 Stack, heap, alignment and sizeof where objects live, padding, alignof, and the address of two locals Open 8.9 Object lifetime raw storage, placement new, an explicit destructor call and std::launder in one sentence Open 8.10 Allocators and std::pmr operator new, a monotonic_buffer_resource and a vector that allocates from it Open

Lessons