Topic: C++0x Wish list (memory management, shared pointers)


Author: John Nagle <nagle@animats.com>
Date: Sun, 16 Jun 2002 05:49:36 GMT
Raw View
Garry Lancaster wrote:

> James Kanze:
>
>>Just don't try and put a raw pointer into two containers of
>>boost::shared_ptr:-).
>
> A-ha, finally all is clear. This is the source of your problems
> with boost::shared_ptr. You must never do what you just
> described. What you are supposed to do is something like this:
>
> boost::shared_ptr<foo> p( new foo );
>
> All subsequent shared_ptrs to the same object must be
> direct or indirect copies of that shared_ptr without any
> intervening raw pointer stage. Raw pointers to a shared_ptr-
> controlled object should only be used as temporaries and
> never to construct a new shared_ptr.


     Now this is why I proposed safe raw pointers
(I was using the term "auto" pointers) some months back.
The raw pointer you get back from boost::shared_ptr needs
an attribute which restricts its use.  Then, compile-time
checking can make the use of smart pointers safe.

         John Nagle
    Animats

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html                       ]