|
Boost Users : |
Subject: Re: [Boost-users] Flyweight: wrapping shared_ptr
From: Thorsten Ottosen (tottosen_at_[hidden])
Date: 2014-10-10 04:42:35
On 09-10-2014 22:23, Joaquin M Lopez Munoz wrote:
> Thorsten Ottosen <tottosen <at> dezide.com> writes:
>
>>
>> Just took a quick look. I would prefer if you used
>> scoped_ptr inside poly_holder.
>
>
> Hi Thorsten,
>
> poly_holder has a very different semantics than scoped_ptr's:
>
> 1. Constructing from a const Base& does not involve heap allocation.
> 2. Copying involves either heap allocation and cloning if the
> copied elements didn't allocate, or ownership transfer otherwise.
Ok, so pick any smart pointer that allows you to do what you want, e.g.
unique_ptr with a custom deleter. I'm just looking at the code and
thinking there's some potential for exception-safety issues which would
probably not be the case if the pointer was stored differently.
Also, I can't figure our the invariant. The pointer can be null, in
which case a call to delete is expensive
(unique_ptr would handle this automatically).
regards
-Thorsten
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net