[Interprocess] Different outputs under bash and gdb

Dear all,
I have a question about proper use of Boost.Interprocess for sharing
custom C++ classes. I recently started using Boost.Interprocess and have
been successful in sharing boost::array, std::vector<float>,
std::vector< boost::array

On 23/11/2010 22:23, Aditya Gadre wrote:
Dear all,
I have a question about proper use of Boost.Interprocess for sharing custom C++ classes. I recently started using Boost.Interprocess and have been successful in sharing boost::array, std::vector<float>, std::vector< boost::array
> etc using boost::interprocess::managed_shared_memory and boost::interprocess::allocator.
You can't share std::vector, it contains raw pointers. You must use boost::interprocess:vector with boost::interprocess::allocator. Best, ion

Ion,
Thank you for your reply. According to Boost.Interprocess documentation,
you *can* share std::vector by using managed shared memory and
Boost.Interprocess allocator (please see "Creating vectors in shared
memory" in "Quick guide for the impatient" in Boost.Interprocess
documentation). Following those guidelines and the example therein , I
have successfully shared std::vector object using following -
using boost::interprocess;
typedef allocator
On 23/11/2010 22:23, Aditya Gadre wrote:
Dear all,
I have a question about proper use of Boost.Interprocess for sharing custom C++ classes. I recently started using Boost.Interprocess and have been successful in sharing boost::array, std::vector<float>, std::vector< boost::array
> etc using boost::interprocess::managed_shared_memory and boost::interprocess::allocator. You can't share std::vector, it contains raw pointers. You must use boost::interprocess:vector with boost::interprocess::allocator.
Best,
ion _______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users

On 24/11/2010 15:21, Aditya Gadre wrote:
Ion,
Thank you for your reply. According to Boost.Interprocess documentation, you *can* share std::vector by using managed shared memory and Boost.Interprocess allocator (please see "Creating vectors in shared memory" in "Quick guide for the impatient" in Boost.Interprocess documentation). Following those guidelines and the example therein , I have successfully shared std::vector object using following -
Believe me, you can't. The example uses boost::interprocess::vector (see using namespace boost::interprocess; and not using namespace std;) http://www.boost.org/doc/libs/1_45_0/doc/html/interprocess/quick_guide.html#... you can't share a std::vector because its internal pointers are normally raw pointers. If two processes map the segment in a different base address it will crash. If you are lucky and both processes map the segment in the same address, then it won't crash, but you have no guarantee for that. For more explanations see: http://www.boost.org/doc/libs/1_45_0/doc/html/interprocess/allocators_contai... Best, Ion

Ion, My appologies...I did not realize that typedef refers to boost::interprocess::vector instead of std::vector. So now I have this new question - what would one need to do in order to share his/her custom C++ classes. Thanks, - Aditya On 11/24/2010 04:47 AM, Ion Gaztañaga wrote:
On 23/11/2010 22:23, Aditya Gadre wrote:
Dear all,
I have a question about proper use of Boost.Interprocess for sharing custom C++ classes. I recently started using Boost.Interprocess and have been successful in sharing boost::array, std::vector<float>, std::vector< boost::array
> etc using boost::interprocess::managed_shared_memory and boost::interprocess::allocator. You can't share std::vector, it contains raw pointers. You must use boost::interprocess:vector with boost::interprocess::allocator.
Best,
ion _______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users

On 24/11/2010 15:41, Aditya Gadre wrote:
Ion,
My appologies...I did not realize that typedef refers to boost::interprocess::vector instead of std::vector. So now I have this new question - what would one need to do in order to share his/her custom C++ classes.
Replace raw pointers with offset_ptr's and avoid storing references and static members and avoid virtuals. See documentation ("Limitations When Constructing Objects In Mapped Regions") for that: http://www.boost.org/doc/libs/1_45_0/doc/html/interprocess/sharedmemorybetwe... Best, Ion

Replace raw pointers with offset_ptr's and avoid storing references and static members and avoid virtuals. See documentation ("Limitations When Constructing Objects In Mapped Regions") for that:
http://www.boost.org/doc/libs/1_45_0/doc/html/interprocess/sharedmemorybetwe...
Ion, The code I already have uses std::vector to store data and it may not be possible to replace it with interprocess::vector. Is there any other container that may be used that has the same interface as std::vector. In the worst case, I can write a very simple class to hold data. Thanks, - Aditya

On 24/11/2010 17:33, Aditya Gadre wrote:
The code I already have uses std::vector to store data and it may not be possible to replace it with interprocess::vector. Is there any other container that may be used that has the same interface as std::vector. In the worst case, I can write a very simple class to hold data.
No, sorry, you need to replace std::vector with an shared memory friendly class. boost::interprocess::vector is the only one I know. In the future (c++0x) std::vector will support boost::interprocess allocators but meanwhile, you'll need to change your code. Best, Ion
participants (2)
-
Aditya Gadre
-
Ion Gaztañaga