[zeromq-dev] Clarifying msg logic

Brian Granger ellisonbg at gmail.com
Tue May 18 04:12:21 CEST 2010


Hi,

We are working on non-copying logic for the Python bindings and have
some questions about the lifecycle of the zmq_msg_t objects.  Here is
our current understanding:


The following create a zmq_msg_t with ref-count = 1

int zmq_msg_init (zmq_msg_t *msg)
int zmq_msg_init_size (zmq_msg_t *msg, size_t size)
int zmq_msg_init_data (zmq_msg_t *msg, void *data, size_t size,
zmq_free_fn *ffn, void *hint)

Next, these increase or decrease the ref-count

int zmq_msg_close (zmq_msg_t *msg)  -> decrease ref-count of msg by 1,
call zmq_free_fn if ref-count = 0
int zmq_msg_copy (zmq_msg_t *dest, zmq_msg_t *src) -> increase
ref-count of src by 1
zmq_socket_send -> decrease ref-count of msg by 1 after sending, if
reaches 0 call zmq_free_fn

Is this thinking correct?

Next, we are wondering how zmq_free_fn behaves when you start calling
zmq_msg_copy.

If you do:

zmq_msg_init_data(msg, ...., // pass in a zmq_free_fn)
zmq_send(msg)  // ref count - 1 and zmq_free_fn is called
zmq_msg_copy(dest, msg)  // is this even valid at this point or do you
have to do this before the send?

If you do the copy before the send, is the zmq_free_fn copied as well?
 Is it called a 2nd time.  It seems like it is not copied as
everything is done by reference.  Correct?

Thanks,

Brian

-- 
Brian E. Granger, Ph.D.
Assistant Professor of Physics
Cal Poly State University, San Luis Obispo
bgranger at calpoly.edu
ellisonbg at gmail.com



More information about the zeromq-dev mailing list