Fwd: [GSoC] __enable_shared_from_this_helper
Jonathan Wakely
jwakely@redhat.com
Fri May 1 08:28:00 GMT 2015
On 01/05/15 01:57 -0400, Fan You wrote:
>>
>> shared_ptr<int[]> p(new int[3]);
>>
>> The shared_count only needs to allocate/deallocate a
>>
>> _Sp_counted_array<int> in both cases, and that has a known size.
Since this seems to be confusing people, what I meant is that
sizeof(_Sp_counted_array<int>) is known.
The implementation has to create _Sp_counted_array<int>, and it can do
that, because it knows everything about the type.
The size of the array that it manages is irrelevant.
>How can _Sp_counted_array<int> get the size when user didn't even pass one?
It doesn't need the size of the array.
>3. Actually it reminds me that user can use current std::shared_ptr
>with array as long as the right deleter are provided.
>>
>> #include <memory>
>>
>> int main()
>> {
>> int array[3];
>> std::shared_ptr<int[3]> p(&array, [](void*){});
>> }
>
>
>This will work because the _Tp = int[3] in original shared_ptr
>implementation. But the new implementation, which, _Tp = int; So, I am
>still not sure why size is not needed to be pass to _Sp_counted_array.
Why do you think it's needed?
shared_ptr<T[]> doesn't have the size, and still works, why do you
think shared_ptr<T[3]> is different?
In both cases:
1) the user creates an array using new[n]
2) the user passes the pointer to a shared_ptr constructor
3) the shared_ptr passes the pointer to a deleter
Why is a size needed for step 2 or 3?
More information about the Libstdc++
mailing list