[asterisk-scf-dev] auto_ptr

David M. Lee dlee at digium.com
Tue Nov 30 09:26:25 CST 2010


On Nov 30, 2010, at 7:44 AM, Simon Perreault wrote:

> Could it be possible to use auto_ptr for now and s/auto_ptr/unique_ptr/
> when C++0x arrives, or is the usage that much different?


It's a bit more than that, since auto_ptr's copy ctor's have to be replaced with unique_ptr's move ctors.  But that's pretty easy.

Honestly, most usages of auto_ptr can be easily replaced with boost::shared_ptr.  And that works for everything from c++98 to c++0x.

It's not that often that you really need strict ownership semantics; usually a shared ownership works well enough for most situations.  The biggest trap there you have to watch out for are cycles (a has shared_ptr to b, b has shared_ptr to a) which would result in a memory leak.

The only auto_ptr references we have in Asterisk SCF are in the logger code, and for those I'm certain we can s/std::auto_ptr/boost::shared_ptr/.

Can we think of any cases where we would need strict ownership?  I guess some well placed #ifdef's could select between auto_ptr and unique_ptr if we did.

It all makes sense.  Should we document on a wiki page?

dave
<><





More information about the asterisk-scf-dev mailing list