[zeromq-dev] Clarifying msg logic

Martin Sustrik sustrik at 250bpm.com
Wed May 19 06:27:30 CEST 2010


>> Now, there's an optimisation for messages below 30 bytes. These are really
>> copied as copying 30 bytes is more efficient than messaging with dynamically
>> allocated memory blocks and reference counts.
> How is the zmq_free_fn handled when the msg content is copied.  Does
> 0MQ take responsibility for deallocating the copy, so zmq_free_fn
> doesn't come into play?

Actually, it works this way:

1. When zmq_msg_init_data() is used, message is never copied, it's 
refcounted and deallocated via free_fn.

2. When zmq_msg_init_size() is used and

   a. message is shorter than 30 bytes, then it is copied and not 
   b. message is larger than 30 bytes, then it is allocated using 
malloc, never copied, refcounted and decallocated using free.


More information about the zeromq-dev mailing list