still trying to get to the bottom of this..appreciate any help. Especially want to know how the VSM data is handled.
On Mon, Mar 4, 2013 at 10:59 AM, Mohit Jaggi <[email protected]> wrote: > This is not fully full but more detailed...'buf' is on stack (so > destructor will be called) and 'm' is on heap(and I havn't called > delete...should I?). I want to understand how zmq treats them. > > context_t ctx(1); > > socket_t *publisher; > > void init() { > > publisher = new socket.... > > publisher.bind(...) > > } > > void publish(myObject) { > > 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 > > } > > main() { > > init(); > > ... > > publish(obj); > > } > > > On Mon, Mar 4, 2013 at 12:51 AM, Pieter Hintjens <[email protected]> wrote: > >> Hi Mohit, >> >> Can you provide a full example? >> >> -Pieter >> >> >> On Mon, Mar 4, 2013 at 8:34 AM, Mohit Jaggi <[email protected]> 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 >> > [email protected] >> > http://lists.zeromq.org/mailman/listinfo/zeromq-dev >> > >> _______________________________________________ >> zeromq-dev mailing list >> [email protected] >> http://lists.zeromq.org/mailman/listinfo/zeromq-dev >> > >
_______________________________________________ zeromq-dev mailing list [email protected] http://lists.zeromq.org/mailman/listinfo/zeromq-dev
