A smart pointer is an abstract data type that simulates an ordinary pointer while adding features such as automatic memory management or bounds checking. The extra features are meant to reduce the bugs that come from misusing raw pointers while keeping the efficiency of a pointer. A smart pointer usually keeps track of the memory it points to and can also manage other resources, such as network connections and file handles. The idea was popularized in the first half of the 1990s in the programming language C++, as an answer to criticism that C++ lacked automatic garbage collection. By making deallocation automatic, smart pointers prevent most memory leaks, and by postponing destruction until an object is no longer in use they remove dangling pointers. Several kinds exist: some use reference counting and others assign sole ownership of an object to one pointer, as with the unique and shared pointer types of C++11. Rust, which avoids raw pointers and uses ownership to dictate lifetimes, also has smart pointers. Languages with garbage collection, such as Java and C#, do not need them for memory safety but can still use similar ideas for resource management.
Facts
Abstraction Level Connections
In Field
Source Smart pointer (Wikipedia)
Sources
1. Smart pointer (Wikipedia)
Features, C++ implementation
In C++, a smart pointer is implemented as a template class that mimics, by means of operator overloading, the behaviors of a traditional (raw) pointer
In Field: Programming Language Theory, Lead, field
Smart pointers were first popularized in the programming language C++ during the first half of the 1990s as rebuttal to criticisms of C++'s lack of automatic garbage collection.
View the SourceReader Challenges (0)
No disputes yet. Spotted an error or a better source? Open the first one.
Sign in to dispute this or suggest a correction.