[zeromq-dev] ZMQ - Send std::shared_ptr via inproc pub-sub?

Rodrigo Farnham rfarnham at gmail.com
Wed Jun 24 19:45:05 CEST 2020


If you can change the class definition, you could use the seldom seen
std::enable_shared_from_this.

On Wed, Jun 24, 2020 at 10:30 BJovke <bjovan at gmail.com> wrote:

> Hi.
>
> You can send a pointer to your shared_ptr and then the receiver should
> copy construct (it's not an actual copy but a reference) it's own
> shared_ptr from it and forget about this pointer.
>
>
> On Wed, Jun 24, 2020, 19:12 Serguei Khasimkhanov <SerKhas at hotmail.com>
> wrote:
>
>> Hello all,
>>
>> I have a publisher thread that has a bunch of shared_ptrs to large chunks
>> of data. Occasionally I want to share some of those shared_ptrs with
>> subscribers (for read-only.) The problem is that ZeroMQ only allows sending
>> binary data, not C++ objects. How can I accomplish this?
>>
>> I was thinking I could allocate a copy of the shared_ptr on the heap,
>> then publish a pointer to it, but since I don't know when the subscribers
>> are done using that pointer, I don't know when to deallocate it.
>>
>> - Ser
>> _______________________________________________
>> zeromq-dev mailing list
>> zeromq-dev at lists.zeromq.org
>> https://lists.zeromq.org/mailman/listinfo/zeromq-dev
>>
> _______________________________________________
> zeromq-dev mailing list
> zeromq-dev at lists.zeromq.org
> https://lists.zeromq.org/mailman/listinfo/zeromq-dev
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.zeromq.org/pipermail/zeromq-dev/attachments/20200624/ae04ff56/attachment.htm>


More information about the zeromq-dev mailing list