Interprocess: limited boost::any in shared memory

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

Interprocess: limited boost::any in shared memory

Boost - Users mailing list
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
_______________________________________________
Boost-users mailing list
[hidden email]
https://lists.boost.org/mailman/listinfo.cgi/boost-users
Reply | Threaded
Open this post in threaded view
|

Re: Interprocess: limited boost::any in shared memory

Boost - Users mailing list


On Wed, 21 Nov 2018 at 20:58, Ferguson, Neil D CTR (US) via Boost-users <[hidden email]> 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 mailing list
[hidden email]
https://lists.boost.org/mailman/listinfo.cgi/boost-users
Reply | Threaded
Open this post in threaded view
|

Re: Interprocess: limited boost::any in shared memory

Boost - Users mailing list
In reply to this post by Boost - Users mailing list
AMDG

On 11/21/2018 11:57 AM, Ferguson, Neil D CTR (US) via Boost-users 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?
>

Yes, it does.  I recommend using variant instead.

In Christ,
Steven Watanabe
_______________________________________________
Boost-users mailing list
[hidden email]
https://lists.boost.org/mailman/listinfo.cgi/boost-users
Reply | Threaded
Open this post in threaded view
|

Re: Interprocess: limited boost::any in shared memory

Boost - Users mailing list
Mr. de Vries,
std::variant looks like it should work splendidly.  boost::variant might be even better.  Thank you.
BTW:  this is my first user group interaction; I hope I am responding correctly.
Neil Ferguson
 

-----Original Message-----
From: Maarten de Vries [mailto:[hidden email]]
Sent: Wednesday, November 21, 2018 1:06 PM
To: [hidden email]
Cc: Ferguson, Neil D CTR (US) <[hidden email]>
Subject: [Non-DoD Source] Re: [Boost-users] Interprocess: limited boost::any in shared memory

All active links contained in this email were disabled. Please verify the identity of the sender, and confirm the authenticity of all links contained within the message prior to copying and pasting the address to a Web browser.


________________________________





On Wed, 21 Nov 2018 at 20:58, Ferguson, Neil D CTR (US) via Boost-users <[hidden email] < Caution-mailto:[hidden email] > > 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 mailing list
[hidden email]
https://lists.boost.org/mailman/listinfo.cgi/boost-users
Reply | Threaded
Open this post in threaded view
|

Re: Interprocess: limited boost::any in shared memory

Boost - Users mailing list
On 26.11.2018 15:43, Ferguson, Neil D CTR (US) via Boost-users wrote:
> Mr. de Vries,
> std::variant looks like it should work splendidly.  boost::variant might be even better.  Thank you.
> BTW:  this is my first user group interaction; I hope I am responding correctly.
> Neil Ferguson
>    

Hi Neil,

it is considered more polite if your text is not at the top of the post
(top-posting) but in-line, just beneath the text your texts responds or
reacts to.

Cheers,

Leon

>
> -----Original Message-----
> From: Maarten de Vries [mailto:[hidden email]]
> Sent: Wednesday, November 21, 2018 1:06 PM
> To: [hidden email]
> Cc: Ferguson, Neil D CTR (US) <[hidden email]>
> Subject: [Non-DoD Source] Re: [Boost-users] Interprocess: limited boost::any in shared memory
[....]


_______________________________________________
Boost-users mailing list
[hidden email]
https://lists.boost.org/mailman/listinfo.cgi/boost-users