Boost.Interprocess with complex/nested classes

I think I finally have a grasp on the basics of the boost:interprocess library, and I've been using it successfully when dealing with relatively simple classes that contain a few member variables that are all standard data types. However, I am now faced with the problem of pushing a rather complex class out into interprocess shared memory and I'm having no luck at all. I'm hoping someone here can help (or can steer me towards an alternate solution). Stripping it down to what I hope are the basics, I have something along these lines: // these first two structures are from the Gnu Scientific Library, so I can't // (or won't) be able to mess with the definition of these structures. typedef struct { size_t size1; size_t size2; size_t tda; double * data; gsl_block * block; int owner; } gsl_matrix; typedef struct { size_t size1; size_t size2; size_t tda; int * data; gsl_block_int * block; int owner; } gsl_matrix_int; // pointers to matricies and other data class MyMatrixClass { gsl_matrix_int* m_pIntMatrix; gsl_matrix* m_pDblMatrix; unsigned int iVal1; unsigned int iVal2; } // some other data-filled class class MyOtherDataClass { std::vector<int> m_vInputs; std::vector<double> m_vOutputs; std::string m_sTitle; bool m_bCorrect; } // and finally, the class that encapsulates the above classes, and // the one that I want to be able to share across processes class SharedClass { MyMatrixClass* m_pNumbers; std::vector<double> m_vDblData; std::vector<MyOtherDataClass> m_vOtherData; } What I need to do is create a vector of SharedClass objects in the interprocess memory space so that multiple processes can access the data. No matter what I try, I cannot seem to find a solution. I It seems like there should be an easier way than making every single member variable along the way an interprocess version (interprocess::vector, interprocess::string, offset_ptr, etc), but maybe not. And even then, I'm not sure how to deal with all the allocators and such, not to mention the GSL library structures. Any help that can be provided will be greatly appreciated. Thank you!

On 11/08/2010 21:33, Rick Hullinger wrote:
I think I finally have a grasp on the basics of the boost:interprocess library, and I've been using it successfully when dealing with relatively simple classes that contain a few member variables that are all standard data types.
However, I am now faced with the problem of pushing a rather complex class out into interprocess shared memory and I'm having no luck at all. I'm hoping someone here can help (or can steer me towards an alternate solution). Stripping it down to what I hope are the basics, I have something along these lines:
You can't share any structure that contains raw pointers, because shared memory is mapped in different address in each process. So you need to replace every member with boost.interprocess alternatives. And if those structures are filled by GNu Scientifice Library, pointers would point to process-local memory (malloc-heap) and that memory isn't shareable with other processes. Best, Ion

Thanks, Ion. Not really what I wanted to hear, but it is what it is.
Last night I saw a message to the group about using Boost.MPI and
serialization. The objects I need to share between processes are
already support serialization, so I'm going to look into the MPI
library next, hopefully that will work.
rick.
2010/8/13 Ion Gaztañaga
On 11/08/2010 21:33, Rick Hullinger wrote:
I think I finally have a grasp on the basics of the boost:interprocess library, and I've been using it successfully when dealing with relatively simple classes that contain a few member variables that are all standard data types.
However, I am now faced with the problem of pushing a rather complex class out into interprocess shared memory and I'm having no luck at all. I'm hoping someone here can help (or can steer me towards an alternate solution). Stripping it down to what I hope are the basics, I have something along these lines:
You can't share any structure that contains raw pointers, because shared memory is mapped in different address in each process. So you need to replace every member with boost.interprocess alternatives. And if those structures are filled by GNu Scientifice Library, pointers would point to process-local memory (malloc-heap) and that memory isn't shareable with other processes.
Best,
Ion _______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
participants (2)
-
Ion Gaztañaga
-
Rick Hullinger