[GSoC] __enable_shared_from_this_helper

Tim Shen timshen@google.com
Thu Apr 30 03:28:00 GMT 2015


On Wed, Apr 29, 2015 at 3:03 AM, Jonathan Wakely <jwakely@redhat.com> wrote:
>> For 3),
>
>
> N.B. make_shared for arrays is *not* part of the Library Fundamentals
> v1 TS. There is a proposal
> (http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2014/n3939.html)
> but it hasn't been approved or included in any working paper.
>
> That means make_shared<T[]> and make_shared<T[N]> are not required for
> this GSoC project.
>
> It would be great if they can be included, but could be left until
> later. I'm fairly sure that the changes needed for make_shared to
> support arrays will be largely independent of any other work and so
> you don't need to consider it now while designing the
> _Sp_counted_array type.
>
>> User will offer allocator, we maintain the length, let's say
>> n, and include n objects *all adjacent with other types of data*, like
>> two counters in _Sp_counted_base and the length. This is possible in C
>> using malloc and flexible member array, but as of my knowledge, it's
>> hard/impossible to implement this using C++ allocator?
>
>
> Certainly not impossible, you don't even need a new type you could
> just reuse the same _Sp_counted_array type:
>
> const size_t aligned_sp =  sizeof(_Sp_counted_array<T>) +
> alignof(_Sp_counted_array<T>) - 1;
>
> const size_t aligned_array = n * sizeof(T) + alignof(T) - 1;
>
> const size_t aligned_len = sizeof(size_t) + alignof(size_t) - 1;
>
> using char_alloc = allocator_traits<Alloc>::rebind_alloc<char>;
> using char_alloc_traits = allocator_traits<char_alloc>;

Is it still as usable if we do a rebind here? [17.6.3.5] seems to make
rebind optional, and there may not exist a char allocator. This was my
major concern.

>> But yeah, for implementing 2) you still need to propagate the length.
>
>
> Why? Am I missing something?

No, it's me who missed something, since I didn't fully follow your
pre-GSoC communications :) I'm not sure how well Fan is on track? Can
Fan briefly illustrate your progress?

As Jon explained, we don't need to explicitly pass around the length,
as long as a customized deleter can take care of it.


-- 
Regards,
Tim Shen



More information about the Libstdc++ mailing list