Usually I use this technique using shared pointers for managing the lifetime of my buffers used in asynchronous operations with boost.asio.
What if my buffer is a std::string
object (which I guess is a little bit special because it does some internal reference counting or so)? Do I still need a shared pointer of a string object which I pass to the handler of the asynchronous operation? Or is the following safe? (And why / why not ?)
void handler()
{
}
void func()
{
std::ostringstream stringbuilder;
// fill stringbuilder
socket.async_send(boost::asio::buffer(stringbuilder.str()), boost:bind(handler));
}