[GSoC] __enable_shared_from_this_helper

Fan You youfan.noey@gmail.com
Tue Apr 28 20:48:00 GMT 2015


Hi,

1. I feel confused about the function
__enable_shared_from_this_helper(); in shared_ptr_base.h.

It's defined as (on line 853) and overloaded to 2 extra version which
accept enable_shared_from_this*:

> template<_Lock_policy _Lp>
>   inline void
>   __enable_shared_from_this_helper(const __shared_count<_Lp>&, ...) noexcept
>   { }


Then it get called in every __shared_ptr_base ctors like this,

> __enable_shared_from_this_helper(_M_refcount, __p, __p);


According to my knowledge, __enable_shared_from_this construct a
weak_ptr in order to safely instantiate a new shared_ptr use only this
pointer. So, does __enable_shared_from_this_helper has no effect until
user trying to do something like this?

> class Test : public ___enable_shared_from_this { };
>
> shared_ptr<Test> (new Test());




2. Also, I am little bit unsure about what _Sp_counted_ptr_inplace does.

It seems to me that when I call allocate_shared<>(); it construct a
single _Sp_counted_ptr_inplace object.
Then, _Sp_counted_ptr_inplace is taking charge of allocating the
needed memory for shared_ptr by using the given allocator.

Does it means, if I want to make make_shared to support array, what I
need to do is change the constructor of _Sp_counted_ptr_inplace to
support allocate size?

Thanks,

Fan



More information about the Libstdc++ mailing list