Boost logo

Boost Users :

Subject: Re: [Boost-users] Interprocess: limited boost::any in shared memory
From: Maarten de Vries (maarten_at_[hidden])
Date: 2018-11-21 20:06:03


On Wed, 21 Nov 2018 at 20:58, Ferguson, Neil D CTR (US) via Boost-users <
boost-users_at_[hidden]> wrote:

> Sirs and madams,
> I hope to use boost interprocess shared memory to pass complex and dynamic
> data structures between processes on a host efficiently. The structures
> will be comprised only of simple primitives (int, float, etc.),
> interprocess basic_string, interprocess containers (vectors and maps),
> containers of containers, and (possible deal killer) boost::any. From the
> interprocess documentation, it _looks_ like the preceding is doable, aside
> from boost::any. The boost::any objects will themselves contain only
> primitives, basic_string, or interprocess vectors of unsigned char. So
> it _looks_ like the data held by the any should be okay. My question:
> does boost::any use pointers, references, or other constructs that preclude
> the class from working in shared memory?
> Thanks for your advice.
> Neil Ferguson
>

Take a look at /usr/include/boost/any.hpp . You will see that the actual
content of the any object is a pointer created with `new` and cleaned up
with `delete`. So this will not work properly in shared memory.

You could consider using std::variant instead, which does not put storage
on the heap (unless contained objects do it themselves, of course).

Kind regards,
Maarten de Vries



Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net