Smart Pointers — Intro

Smart pointers are coming. C++ already provides auto_ptr< T > as part of the standard library, and C++0x will be adding shared_ptr< T > and weak_ptr< T >, which are now part of TR1. Boost provides a couple other smart pointers.

Smart pointers help manage memory using ownership and reference counting. When using them you have to watch for circular dependencies, which you don’t have to worry about in garbage-collecting languages like Lisp, Python, Ruby, and Java. Since C++ doesn’t come with a garbage collector you have to manage memory yourself, and smart pointers are a tool you can use. A memory management scheme is not the same thing as automatic garbage collection.

I’m going to be writing a few short posts about smart pointers in the next few days. This is just an introduction and some links.

← Previous Page