Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p><a href="http://en.wikipedia.org/wiki/Smart_pointer" rel="noreferrer">Smart pointer</a> is a pointer-like type with some additional functionality, e.g. automatic memory deallocation, reference counting etc.</p> <p>Small intro is available on page <a href="http://ootips.org/yonat/4dev/smart-pointers.html" rel="noreferrer">Smart Pointers - What, Why, Which?</a>.</p> <p>One of the simple smart-pointer type is <a href="http://en.cppreference.com/w/cpp/memory/auto_ptr" rel="noreferrer"><code>std::auto_ptr</code></a> (chapter 20.4.5 of C++ standard), which allows to deallocate memory automatically when it out of scope and which is more robust than simple pointer usage when exceptions are thrown, although less flexible.</p> <p>Another convenient type is <a href="http://www.boost.org/doc/libs/1_36_0/libs/smart_ptr/shared_ptr.htm" rel="noreferrer"><code>boost::shared_ptr</code></a> which implements reference counting and automatically deallocates memory when no references to object remains. This helps avoiding memory leaks and is easy to use to implement <a href="http://en.wikipedia.org/wiki/Resource_Acquisition_Is_Initialization" rel="noreferrer">RAII</a>.</p> <p>Subject is covered in depth in book <a href="http://rads.stackoverflow.com/amzn/click/0201734842" rel="noreferrer">"C++ Templates: The Complete Guide" by David Vandevoorde, Nicolai M. Josuttis</a>, chapter Chapter 20. Smart Pointers. Some topics covered:</p> <ul> <li>Protecting Against Exceptions</li> <li>Holders, (note, <a href="http://en.cppreference.com/w/cpp/memory/auto_ptr" rel="noreferrer">std::auto_ptr</a> is implementation of such type of smart pointer)</li> <li><a href="http://en.wikipedia.org/wiki/Resource_acquisition_is_initialization" rel="noreferrer">Resource Acquisition Is Initialization</a> (This is frequently used for exception-safe resource management in C++)</li> <li>Holder Limitations</li> <li><a href="http://en.wikipedia.org/wiki/Reference_counting" rel="noreferrer">Reference Counting</a></li> <li>Concurrent Counter Access</li> <li>Destruction and Deallocation</li> </ul>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload