Boost logo

Boost Users :

Subject: [Boost-users] Force boost::asio::buffer to copy by value.
From: Slav (slavmfm_at_[hidden])
Date: 2011-05-04 06:07:35


Hello. I use boost::asio::buffer to send a message using

void Send(const std::string& messageData)
{
    socket.async_write(boost::asio::buffer(messageData), ...);
}

And encounter "string iterator not dereferencable" runtime error somewhere
within io_service' thread. When I create objects' variable to store message
data for the buffer:

void Send(const std::string& messageData)
{
    this->tempStorage = messageData;
    socket.async_write(boost::asio::buffer(this->tempStorage), ...);
}

the error is never occured. std::string (to which messageData is referenced
to) is freed almost right after Send() calling - does boost::asio::buffer
stores just a reference to object? If so, how can I force it to store the
data by value?



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