[zeromq-dev] How to do zero-copy multi-part messages without transfering the ownership of the data to ZMQ?

lists at chuckremes.com lists at chuckremes.com
Tue Mar 28 15:18:33 CEST 2017


> On Mar 28, 2017, at 7:57 AM, Stephan Opfer <opfer at vs.uni-kassel.de> wrote:
> 
> Hi,
> 
> I would like to do what is described in this tutorial here: http://zeromq.org/blog:zero-copy
> 
> But, I don't like to transfer the ownership to ZMQ, because it will delete the data when the message is sent.
> 
> My application is more like this:
> 
> Several autonomous robots inform each other from each other from time to time about the results of some calculuations, e.g., path planning results.
> 
> These results are created for further processing and need to be kept in the ownership of the process itself. They can be send with zero-copy, because the wont be altered anymore, but should not be deleted.
> 
> Any suggestions?

I would suggest passing a delete function to zeromq that is a no-op or just sets a flag that your process can retrieve. There is no real “transfer of ownership” happening within the library. The transfer that the documentation talks about is the *responsibility* to free the memory buffer once it has been sent by zeromq.

If your robot processes need to continue owning the buffer then just pass a function to zeromq that, when called, will set a flag in your robot process that indicates zeromq has finished with the buffer. Then your library can reuse the memory, deallocate it, or whatever.


More information about the zeromq-dev mailing list