This is the mail archive of the
libstdc++@gcc.gnu.org
mailing list for the libstdc++ project.
Re: Fwd: [GSoC] __enable_shared_from_this_helper
- From: Jonathan Wakely <jwakely at redhat dot com>
- To: Fan You <youfan dot noey at gmail dot com>
- Cc: libstdc++ <libstdc++ at gcc dot gnu dot org>
- Date: Fri, 1 May 2015 09:28:15 +0100
- Subject: Re: Fwd: [GSoC] __enable_shared_from_this_helper
- Authentication-results: sourceware.org; auth=none
- References: <20150428215349 dot GG3618 at redhat dot com> <CALvpekGhEJfEWdHmtOyco-Ua=sPjk4yhpFFE7Fzffy9cTmnVbA at mail dot gmail dot com> <CAG4ZjN=a9nvQ3CgqRiSze-fbUvh0u69WQQdehS5+mFXsvtSP=A at mail dot gmail dot com> <20150429100344 dot GH3618 at redhat dot com> <CAG4ZjNnFTOtEoSPdzv9Dip8s7O6o4ToL2+N-j_oEuxvrD1spLA at mail dot gmail dot com> <20150430112352 dot GR3618 at redhat dot com> <CAG4ZjNmgtF-7jE17d=e8fK_iMhkDHT783Qv1sYpt6MPKsmLL=A at mail dot gmail dot com> <20150430174827 dot GU3618 at redhat dot com> <CALvpekGSvSvg=WcF4w2r3LQ377azPfsAKfLtA5pFm3OKz6DesA at mail dot gmail dot com> <CALvpekHhL1rO-AwyinbmRbrukDj+cATM2n-P6wy2oUNpwieVrA at mail dot gmail dot com>
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?