[lldb-dev] std::shared_ptr, RTTI, and LLDB

Howard Hinnant hhinnant at apple.com
Thu Jun 10 17:56:08 PDT 2010


Greg Clayton wrote:

>  We use a lot of shared pointers, though we aren't currently using the fancy RTTI aspects of it. We really want _some_ sort of shared pointer so we can have STL collections of objects that don't move around when collections grow. Also with a lot of our partial parsing we can determine how many objects there are in a collection, resize the collection to contain that many objects, then lazily populate such objects.

<snip>

> As long as it is a reference counted pointer that doesn't require us to build boost. 
> 
> We can easily replace all shared pointers within LLDB by redefining "lldb::SharedPtr" in lldb-types.h. 
> 
> Feel free to experiment, though I would rather not pull in all of boost just to get a shared pointer... We currently get that from a tr1 directory on MacOSX. Does linux have a similar implementation in tr1 (#include <tr1/memory>)? We do make use of putting objects into shared pointers that are the virtual base class impementations of pure virtual protocols, so I am not sure if this requires RTTI (I can't remember what role RTTI plays in the shared pointers...).

libc++ (http://libcxx.llvm.org/) has a std::shared_ptr:

http://llvm.org/svn/llvm-project/libcxx/trunk/include/memory

If desired I can pull the shared_ptr bits out of this file, reduce dependencies as much as possible, pull the rtti bits, and ship you a custom shared_ptr.

I should first peruse your source and find out just how much shared_ptr you need.  For example if you don't need weak_ptr or enable_shared_from_this, I can trim shared_ptr from two reference counts down to one.  This trimming is already done in libc++ as I needed it for locale anyway.

-Howard





More information about the lldb-dev mailing list