[zeromq-dev] Non-copying recv
Martin Sustrik
sustrik at 250bpm.com
Fri May 21 07:43:32 CEST 2010
Hi Brian,
> We are putting the final touches to the non-copying send/recv in the
> Python bindings and I have a question about the non-copy recv.
>
> The following will now work in a non-copying manner:
>
>>>> msg = s.recv(copy=False)
>>>> type(msg)
> 'Message'
>>>> s2.send(msg)
>
> But in this simple case the contents of the msg are not used in any
> way by the app. What if the app wants to use the contents of the
> Message and even change it, but not make a copy? An example would be
> to pass the msg buffer to an array, which is then modified in place:
>
>>>> msg = s.recv(copy=False)
>>>> a = new_array(msg)
>>>> a[0,0] = 4.0 # inplace modification
>
> It seems like the array object would need to take ownership of the
> buffer and that 0MQ couldn't deallocate the buffer.
>
> Is this type of thing possible? I could simple increase the 0MQ
> ref-count to prevent 0MQ from freeing the message, but I am not sure
> that makes sense.
When you receive a message the ownership is passed to you. You have a
message wih refcount of 1. It gets deallocated when you call
zmq_msg_close. You can change the content, you can copy it. Obviously,
once you copy it, changing the content would be visible on every copy.
Martin
More information about the zeromq-dev
mailing list