Some questions on allocators and shared_ptr

Alex Dubov oakad@yahoo.com
Thu Oct 21 18:57:00 GMT 2010


Jonathan Wakely <jwakely.gcc <at> gmail.com> writes:

> 
> Thanks for your interest in improving rope!  Do you have a GCC
> copyright assignment in place?
> 

No, I don't have any, and the instructions look fairly confusing.

I wrote a preliminary version of the "counted_ptr" class, implementing the
discussed functionality. Shall I post it to the list as is? For now, it can be
seen here: http://github.com/oakad/mx2sphinx/raw/devel/rope/counted_ptr.h

Major departures from shared_ptr are:
1. counted_ptr has only one member, which is the held object pointer itself.
2. To make p.1 possible, no raw pointer constructor is provided, only
make_counted and allocate_counted. Given that variadic argument forwarding is
here to stay, I presume, it's a reasonable price for fast dereference
operation.
3. I'm using pointer arithmetic to get to the enclosing refcount object from
the held object pointer.
4. Variants of allocate_counted and make_counted are provided, which allow to
specify an "extra" byte storage to be allocated together with the held object.
5. Allocator is only optionally stored and even then, only in the form of base
(empty object optimization pattern). Here I also wonder, why there's nothing
like boost::compressed_pair in the library? It'll surely be nicer than various
alloc_hider classes around the place.






More information about the Libstdc++ mailing list