|
Boost Users : |
Subject: Re: [Boost-users] [Interprocess] shared_ptr in shared memory and inheritance
From: Gaetan Gaumer (gaetan.gaumer_at_[hidden])
Date: 2009-02-10 03:47:10
2009/2/9 Ion Gaztañaga <igaztanaga_at_[hidden]>
> Emil Dotchevski wrote:
>
>> You're probably doing something wrong, shared_ptr doesn't require
>> virtual destructor to call the correct destructor. Here is a working
>> example: http://codepad.org/sktELTDk
>>
>
> Yes, it needs a virtual destructor if it's a shared_ptr to the base class,
> otherwise you can't achieve type erasure. This virtual call does not happen
> with boost::interprocess::shared_ptr because virtuality is forbidden in
> shared memory.
>
> Regards,
>
> Ion
>
In boost::shared_ptr doc
http://www.boost.org/doc/libs/1_38_0/libs/smart_ptr/shared_ptr.htm#Members
It's said :
"This constructor has been changed to a template in order to remember the
actual pointer type passed. The destructor will call *delete* with the same
pointer, complete with its original type, even when *T* does not have a
virtual destructor, or is *void*."
So I thought Emil is right and that's why I tried :
base_shared_ptr baseSP =
make_managed_shared_ptr(segment.construct<derived>(anonymous_instance)(2,3.0),
segment);
I even tried something like this :
base_shared_ptr baseSP =
base_shared_ptr(segment.construct<derived>(anonymous_instance)(1,3.0),
segment.get_allocator<void>(),
segment.get_deleter<derived>() );
But this does not compile.
But as boost::interprocess::shared_ptr is based on boost::shared_ptr I
thought it could work....
Is it really impossible to achieve the same behavior in
boost::interprocess::shared_ptr than in boost::shared_ptr ?
I looked at the code (of both shared_ptr.hpp) and I don't see where is the
lock.
But I'm surely not enough skilled to write the right ctor by myself.
But It would solve my problem, isnt'it ?
Gaetan
PS : By the way, thanks Ion and others for this great work on boost in
general and the Interprocess library in particular.
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