zeromq / libzmq

ZeroMQ core engine in C++, implements ZMTP/3.1
https://www.zeromq.org
Mozilla Public License 2.0
9.53k stars 2.34k forks source link

subscriber and publisher show different situation with differet created way when they receive messages. #4565

Open fengmao31 opened 1 year ago

fengmao31 commented 1 year ago

Please use this template for reporting suspected bugs or requests for help.

Environment

Issue description

I find subscriber and publisher show different situation with differet created way when they receive messages. I test the different situation that zmq publisher use stack or heap, while zmq recevier use stack

Experiment

publisher

when I use stack to create zmq::context_t and zmq::socket_t, zmq subscriber lost first messages from zmq publisher. byuQoytv1s image

when I use heap to create zmq::context_t and zmq::socket_t, zmq subscriber can get all messages from zmq publisher. 6R1IDZYVa8 image

subscriber

image

fengmao31 commented 1 year ago

It is because in a huge while. the stack variable is created and destroyed repeatly. while the zmq::context_t context and zmq::socket_t publisher is not in the while. only the make _unique operating in the while.

But why repeatly make _unique looks like not realloc the momery?