This is the mail archive of the
libstdc++@gcc.gnu.org
mailing list for the libstdc++ project.
Re: [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: Tim Shen <timshen91 at gmail dot com>, libstdc++ <libstdc++ at gcc dot gnu dot org>
- Date: Tue, 28 Apr 2015 22:53:49 +0100
- Subject: Re: [GSoC] __enable_shared_from_this_helper
- Authentication-results: sourceware.org; auth=none
- References: <CALvpekGVZEMtGN5MKVXrArG5cKJhqDQjsfgjdFZYk0=H=7+V_Q at mail dot gmail dot com> <20150428215024 dot GF3618 at redhat dot com>
On 28/04/15 22:50 +0100, Jonathan Wakely wrote:
On 28/04/15 16:48 -0400, Fan You wrote:
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.
Right.
Then, _Sp_counted_ptr_inplace is taking charge of allocating the
needed memory for shared_ptr by using the given allocator.
No, all the memory is already allocated by the time the
_Sp_counted_ptr_inplace's lifetime begins.
_Sp_counted_ptr_inplace contains the shared_count but also a buffer
where the object will be created.
When you use _Sp_counted_ptr the object is allocated separately, but
when you use _Sp_counted_ptr_inplace the object lives inside the
_Sp_counted_ptr_inplace so there is no separate allocation.