[zeromq-dev] question about message buffer
Pieter Hintjens
ph at imatix.com
Mon Mar 4 09:51:53 CET 2013
Hi Mohit,
Can you provide a full example?
-Pieter
On Mon, Mar 4, 2013 at 8:34 AM, Mohit Jaggi <mohitjaggi at gmail.com> wrote:
> Hi,
> I am a little confused about how messages and buffers are handled in zmq. In
> the following example, valgrind finds a message leak for 'm'.
> 1) Should I call delete for 'm' after the send?
> 2) zmq will keep the buffer(data) but free memory for 'm' if I do this?
> 3) What about 'topic'? It is on stack and data is small, so I guess it uses
> the vsm area to store the message?
> 4) Will send for 'topic' make a copy of the data then?
>
> Mohit.
>
>
> string buf;
>
> myObject.SerializeToString(&buf);
>
> message_t m = new message_t(buf.size());
>
> memcpy((void*) m.data(), buf.c_str(), buf.size());
>
> string topic(string("X") + string("Y") + string("Z"));
>
> publisher->send(topic.c_str(), topic.size(), ZMQ_SNDMORE); //topic
>
> publisher->send(m); //data
>
>
> _______________________________________________
> zeromq-dev mailing list
> zeromq-dev at lists.zeromq.org
> http://lists.zeromq.org/mailman/listinfo/zeromq-dev
>
More information about the zeromq-dev
mailing list