[zeromq-dev] how to receive a message into a static buffer?
Aamir M
intuitionist at gmail.com
Mon May 4 16:53:31 CEST 2009
Hi Martin,
Is the concept of a user-provided receive buffer completely out of the
question? What if the user provided 0MQ with a buffer and promised not to
touch the buffer until it gets a pointer from 'receive'? Couldn't the copy
be eliminated in this way? I think this would be a very useful feature for
high performance streaming.
Regards,
Aamir
On Mon, May 4, 2009 at 10:06 AM, Martin Sustrik <sustrik at fastmq.com> wrote:
> Hi Aamir,
>
>
> I would like to receive a message into a pre-allocated buffer. I tried the
>> following:
>>
>> void* buffer = &mybuffer;
>> zmq::message_t msg( buffer, sizeof(T), NULL );
>> api-> receive( &msg, true );
>> assert( msg.data() == datap ); // fails here
>>
>> I have to resort to a memcpy:
>>
>> zmq::message_t msg();
>> api-> receive( &msg, true );
>> memcpy( &mybuffer, msg.data(), sizeof(T) );
>>
>> I want to avoid the copy and I must have the message data in the static
>> buffer. Is this possible?
>>
>
> The data are read from the network asynchronously in the background. Thus
> the buffer is allocated there. When you do 'receive' the buffer is passed to
> your application (in form of pointer). Note that this way 0MQ is able to
> transfer the data without copying it.
>
> In case you want to get the data to your own buffer, you have to copy it.
> There's no way to avoid the copy as your buffer doesn't even have to exist
> at the time when the data are retrieved from the network.
>
> Martin
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.zeromq.org/pipermail/zeromq-dev/attachments/20090504/0145f2e3/attachment.htm>
More information about the zeromq-dev
mailing list