Smart pointers solve the problem of managing the lifetime of resources (typically dynamically allocated objects[1]). Smart pointers come in different flavors. Most share one key featureautomatic resource management. This feature is manifested in different ways, such as lifetime control over dynamically allocated objects, and acquisition and release of resources (files, network connections). The Boost smart pointers primarily cover the first casethey store pointers to dynamically allocated objects, and delete those objects at the right time. You might wonder why these smart pointers don't do more. Couldn't they just as easily cover all types of resource management? Well, they could (and to some extent they do), but not without a price. General solutions often imply increased complexity, and with the Boost smart pointers, usability is of even higher priority than flexibility. However, through the support for custom deleters, Boost's arguably smartest smart pointer (boost::shared_ptr) supports resources that need other destruction code than delete. The five smart pointer types in Boost.Smart_ptr are tailor-made to fit the most common needs that arise in everyday programming.
|