ECS 36B Lecture Notes - Lecture 13: Smart Pointer
ECS 36B verified notes
13/26View all
Document Summary
Ecs 36b - lecture 13 - smart pointers. When the smart pointer is deleted, the memory that it points to is also erased. If used correctly, your program will no longer be susceptible to memory leaks. A smart pointer should only be used when pointing to dynamically-allocated memory. References should be preferable over pointers for the sole reason that references will. Avoids dereferencing of pointers that no longer point to anything. Used if the data belongs to a single owner. Used if the data belongs to multiple owners. Looks at data in a shared pointer, while having no ownership over it. Most likely will only use unique pointers for the sake of this course. Have to include memory when using these smart pointers. For a unique pointer that points to nullptr. Unique pointers are dereferenced the same way as normal pointers. Destroy whatever the unique pointer is pointing to.