diff --git a/shared_ptr.htm b/shared_ptr.htm index cdf2b93..33db24b 100644 --- a/shared_ptr.htm +++ b/shared_ptr.htm @@ -10,6 +10,14 @@

c++boost.gif (8819 bytes)Class shared_ptr

+

Introduction
+Synopsis

+Members
+Example
+Handle/Body Idiom
+Frequently Asked Questions
+Smart Pointer Timings

+

Introduction

Class shared_ptr stores a pointer to a dynamically allocated object. (Dynamically allocated objects are allocated with the C++ new expression.)   The object pointed to is guaranteed to be deleted when @@ -33,7 +41,7 @@ object A dangling with a use_count() of 1.

The class is a template parameterized on T, the type of the object pointed to.   T must meet the smart pointer Common requirements.

-

Class shared_ptr Synopsis

+

Class shared_ptr Synopsis

#include <boost/smart_ptr.hpp>
 namespace boost {
 
@@ -112,7 +120,7 @@ than supplying a full range of comparison operators (<, >, <=, >=).<
 name BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION is defined.

The current implementation does not supply the member template functions if the macro name BOOST_NO_MEMBER_TEMPLATES is defined.

-

Class shared_ptr Members

+

Class shared_ptr Members

shared_ptr element_type

typedef T element_type;

Provides the type of the stored pointer.

@@ -218,19 +226,25 @@ which uses a shared_ptr<> to an incomplete type to hide the implementation.   The instantiation of member functions which require a complete type occurs in the shared_ptr_example2.cpp implementation file.

-

FAQ

+

Frequently Asked Questions

Q. Why doesn't shared_ptr have template parameters supplying traits or policies to allow extensive user customization?
A. Parameterization discourages users.  Shared_ptr is carefully crafted to meet common needs without extensive parameterization. Someday a highly configurable smart pointer may be invented that is also very easy to use and very hard to misuse.  Until then, shared_ptr is the -smart pointer of choice for a wide range of applications.

+smart pointer of choice for a wide range of applications.  (Those +interested in policy based smart pointers should read Modern +C++ Design by Andrei Alexandrescu.)

+

Q. Why doesn't shared_ptr use a linked list implementation?
+A. A linked list implementation does not offer enough advantages to +offset the added cost of an extra pointer.  See timings +page.

Q. Why don't shared_ptr (and the other Boost smart pointers) supply an automatic conversion to T*?
A. Automatic conversion is believed to be too error prone.


-

Revised 24 May, 2001 +

Revised 12 July, 2001

© Copyright Greg Colvin and Beman Dawes 1999. Permission to copy, use, modify, sell and distribute this document is granted provided this copyright