ECS 36B Lecture Notes - Lecture 13: Smart Pointer

49 views3 pages
Verified Note

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.

Get access

Grade+20% off
$8 USD/m$10 USD/m
Billed $96 USD annually
Grade+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
40 Verified Answers
Class+
$8 USD/m
Billed $96 USD annually
Class+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
30 Verified Answers

Related Documents