Boost logo

Boost Users :

Subject: Re: [Boost-users] Problem with boost ::interprocess::string
From: Andrew Holden (aholden_at_[hidden])
Date: 2011-12-22 14:49:33


On Thursday, December 22, 2011 11:42 AM, Josmon Paul wrote:
>
> Hi All
> I am totally new to the boost library. i will start with my
> problem. Currently i am using boost shared memory for storing
> a vector list. In the vector list each elements are string type.
> I am using boost::interprocess::string type. But i was not
> able to use the string size of more than 10 as above it is
> causing segmentation fault. If it is below 10 there is no
> issues. Pleasehelp me how to fix this issue.

By default, boost::interprocess::string uses the standard (non-interprocess) allocator. Below 10 characters, the string doesn't allocate any additional storage; it stores the string in the string object itself. Beyond 10 characters, it allocates a buffer to store the string.

If you're storing the string in a shared region (which I assume you are), you need to use the following string type:

boost::interprocess::basic_string <char, std::char_traits <char>, same_allocator_type_as_your_vector>

Then, each time you construct a string, pass the same instance of that allocator as you passed to the vector's constructor.


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