Boost logo

Boost Users :

Subject: Re: [Boost-users] [interprocess] Segmentation fault when using std::string in stl::maps in shared memory
From: Ravi (lists_ravi_at_[hidden])
Date: 2008-10-20 11:15:36


On Monday 20 October 2008 02:38:05 hamsinv wrote:
> After a few search I found out that we cannot use std::string. Instead we
> should try with interprocess::basic_string. Can anyone guide me through
> this.

The fundamental issue is that objects which allocate memory on the heap cannot
be used with shared memory. Consider what happens when you use a construct a
string in shared memory. Upon construction which requires storage (such as
assigning it an initial value), the string constructor allocates some memory
on the heap (not in the shared memory segment), which is visible only in the
constructing process. Using the memory in the other processes tries to access
those memory locations which results in undefined behavior. In order to
overcome this problem, you need to use a shared-memory-aware string, such as
interprocess::basic_string.

Please read the section named "Limitations When Constructing Objects In Mapped
Regions" in the interprocess manual for more information.

Regards,
Ravi


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