Re: [Boost-users] [boost] [shared_ptr] A smarter smart pointer proposal for dyn
Hello Dotchevski, Could you please elaborate? Thanks. B/Rgds Max ----- Original Message ----- From: Emil Dotchevski To: boost@lists.boost.org Subject: Re: [boost] [shared_ptr] A smarter smart pointer proposal for dynamic libraries Date: 2008-12-24 12:37:33 As far as I can tell, the only reason your reset() appears to work is that it is inlined in the executable. The compiler doesn't guarantee inlining, so in general it will crash anyway. The solution to this problem is to inject the DLL's lifetime into any shared_ptrs obtained from that DLL; that is, make the shared_ptr keep the DLL afloat. This can be done easily (and non-intrusively) using shared_ptr's aliasing constructor. Emil Dotchevski Reverge Studios, Inc. http://www.revergestudios.com/reblog/index.php?n=ReCode ------------------------------------------------------------------- 新浪空间——与朋友开心分享网络新生活!(http://space.sina.com.cn/ )
On Wed, Dec 24, 2008 at 3:06 AM, Max
Hello Dotchevski,
Could you please elaborate?
Let's say you have a shared_ptr<void const> that keeps the DLL afloat, and another shared_ptr<T> which requires the module to remain loaded. You could do: template <class T> struct wrapper { shared_ptr<T> obj_; shared_ptr<void const> lifetime_; wrapper( shared_ptr<T> const & obj, shared_ptr<void const> const & lifetime ): obj_(obj), lifetime_(lifetime) { } }; template <class T> shared_ptr<T> inject_lifetime( shared_ptr<T> const & obj, shared_ptr<void const> const & lifetime ) { shared_ptr< wrapper<T> > w( new wrapper<T>(obj,lifetime) ); return shared_ptr<T>(w,w.obj_->get()); } Emil Dotchevski Reverge Studios, Inc. http://www.revergestudios.com/reblog/index.php?n=ReCode
participants (2)
-
Emil Dotchevski
-
Max