[zeromq-dev] [PATCH] zmq::msg_t::const_data for const correctness?

Martin Sustrik sustrik at 250bpm.com
Fri May 27 10:16:52 CEST 2011

On 05/27/2011 10:05 AM, Ilja Golshtein wrote:
> Yes, it was discussed here
> http://thread.gmane.org/gmane.network.zeromq.devel/8565/focus=8603
> Attaching the patch (again)
> It suggests two overloaded data() methods. The new one is const and
> returns const void*.

Yes. This is a better approach but still doesn't deliver consistent 
const semantics.

Implementing CoW behaviour to get the semantics consistent in 
std::string way is probably not that good an idea because of the 
performance impact of message copying.

One solution that comes to mind is changing the zmq_msg_copy function in 
such a way that it closes the original non-const message and produces 
two const messages.

That way the user can't shoot himself in the leg by copying a message 
object (which makes the buffer shared) and overwriting the data in one 
instance behind other instance's back.

     int zmq_msg_copy (const zmq_msg_t *src, const zmq_msg_t **dest1, 
const zmq_msg_t **dest2);


More information about the zeromq-dev mailing list