[zeromq-dev] Clarifying msg logic

Brian Granger ellisonbg at gmail.com
Thu May 20 20:44:33 CEST 2010


On Tue, May 18, 2010 at 9:27 PM, Martin Sustrik <sustrik at 250bpm.com> wrote:
> Brian,
>
>>> 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 refcounted.
>  b. message is larger than 30 bytes, then it is allocated using malloc,
> never copied, refcounted and decallocated using free.

OK thanks, this definitely helps.

Cheers,

Brian

> Martin
>



-- 
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