|
Boost Users : |
Subject: Re: [Boost-users] [bind] Doubt regarding the use of shared_ptr with boost.bind
From: Shiou Ming Lee (shiouming.lee_at_[hidden])
Date: 2010-09-23 12:59:22
On Thu, Sep 23, 2010 at 9:25 AM, Igor R <boost.lists_at_[hidden]> wrote:
> > m_ioService.post(m_strand.wrap(
> > boost::bind(&LogWriter::append,
> > (*logWritersItr), _logMessage, _logLevelString)
> > ));
> >
> > The second param of Bind, (*logWritersItr), is a shared_ptr of
> LogWriter's
> > subclass. The signature of LogWriter::append() is as following:
> >
> > virtual void append(const std::string& _logMessage, const std::string&
> > _logLevelString) = 0;
> >
> > Base on document at
> > http://www.boost.org/doc/libs/1_44_0/libs/bind/bind.html, the way I use
> bind
> > will duplicate a copy of that shared_ptr. Any idea when will the
> duplicated
> > shared_ptr become invalid so that the reference count decreases by one?
>
> bind() takes your shared_ptr by value, so it won't become "invalid".
> After io_service executes your functor, it will be destroyed, so all
> its internal copies of that shared_ptr will be destroyed as well.
> _______________________________________________
> Boost-users mailing list
> Boost-users_at_[hidden]
> http://lists.boost.org/mailman/listinfo.cgi/boost-users
I think I don't quite completely understand functor.., is it by C++ that a
functor will be destroyed automatically once executed? Or is this a feature
from boost.bind?
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