I have the following functions:
void MyLib::sendMessage(const std::string& message) {
m_xIOService.post( boost::bind(&VoIPPhone::onSendMessage, this, message) );
}
void MyLib::onSendMessage(const std::string& message) {
m_xVoIPClient.sendMessage(message);
}
So I call sendMessagein one thread and onSendMessage will be invoked in main thread.
The question is will be message string copied by boost in this case or not. If no – how can I pass string into onSendMessage function and be sure that there will no memory leak and message string is valid, not deleted object?
onSendMessagewill be invoked in one of the threads that executem_xIOService::run– not in the main thread.All
bindarguments are copied, somessagewill be copied as well. Whenever you want to passbindparameters by reference, useboost::refwrapper.