I asked a question about boost::asio here but some additional questions came up today. I have some very simple Server Client structure and at one point this async_write
command:
ushort _nSetupReceiveBuffer[_nDynamicSize];
boost::asio::async_write(m_oSocket, boost::asio::buffer(&_nSetupReceiveBuffer, _nDynamicSize),
[this, self](boost::system::error_code _oError, std::size_t)
{
std::cout << _nSetupReceiveBuffer.size() << std::endl;
});
Unfortunately it results in error: ‘_nSetupReceiveBuffer’ is not captured
error.
So my questions are:
How can I capture
nSetupReceiveBuffer
or better capture its reference? (Capturing its reference with[this, self, &_nSetupReceiveBuffer]
builds but results in Segmentation fault (core dumped) error even before any data is received, since, I assume, it is executed as callback the original variable is already deleted.)I use ushort because I want to transmit
cv::Mat
images withCV_16U
setting and tried to follow this idea. Do you have other ideas how to transmit cv::Mat files via boost? I can only use lossless containers, but I want to avoid high CPU loads. In my case the bandwith shouldn't be the problem. However that is only half of the truth, I tried to use a serializer which serializes the image to a string, which worked fine but increased the size dramatically :-(- To avoid the problems from 1. I could make
_nSetupReceiveBuffer
a member variable, but I need to allocate it dynamically at runtime, which I don't know how to do? And a second drawback would be, that the variable typeushort
is fixed, but I want to be flexible, e.g. if I have another video stream ofCV_8U
type, I need to change it touchar
. - My last approach was to
reshape()
thecv::Mat
and use astd::vector<ushort>
as member variabel which stores the single values. Is that reasonable or only generating large overhead? Can I define a vector as member variable without a type specified, or should I define one for each type and then just use the appropriate one?
Thank you for your help.