Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6049437
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T07:34:38+00:00 2026-05-23T07:34:38+00:00

I used boost::interprocess::managed_(windows_)shared_memory::construct to construct an interprocess vector holding an own class, which has

  • 0

I used boost::interprocess::managed_(windows_)shared_memory::construct to construct an interprocess vector holding an own class, which has a member variable of type std::string and another of type std::vector, so:

class myclass
{
    public:
        myclass()
        {

        }

        std::string _mystring;
        std::vector < int > _myintvector;
};

template < class _type >
struct typedefs
{
    typedef boost::interprocess::managed_windows_shared_memory     _memory;
    typedef _memory::segment_manager                               _manager;
    typedef boost::interprocess::allocator < _type, _manager >     _allocator;
    typedef boost::interprocess::vector < _type, _allocator >      _vector;
};

typedef typedefs < myclass > tdmyclass;

int main ()
{
    using namespace boost::interprocess;

    managed_windows_shared_memory mem ( open_or_create, "mysharedmemory", 65536 );
    tdmyclass::_vector * vec = mem.construct < tdmyclass::_vector > ( "mysharedvector" ) ( mem.get_segment_manager() );
    myclass mytemp;

    mytemp._mystring = "something";
    mytemp._myintvector.push_back ( 100 );
    mytemp._myintvector.push_back ( 200 );

    vec->push_back ( mytemp );

    /* waiting for the memory to be read is not what this is about, 
    so just imagine the programm stops here until everything we want to do is done */
}

I just did this for testing, I expected neither std::string nor std::vector to be working, yet, if I read it in from another process, std::string actually works, it contains the string I assigned. That really surprised me.
The std::vector on the other side only partially works, the value returned by size() is correct, but the programm crashes if I want to access an iterator or by using operator[].

So, my question is, why is it that way ? I mean, I never actually read the STL implementations of the SDK of Visual Studio, but isn’t std::string just an std::vector with extra functions suited for strings ? Don’t they both use std::allocator – which would mean, that BOTH std::string and std::vector wouldn’t work in shared memory ?

Googling for this doesn’t really result into anything but boost::interprocess::vector, and thats not what I searched. So I hope someone can give me some details about whats going on ^^

PS: If I did a typo in the above code, please pardon me, I just wrote it right now in this pages editor and im kinda way too used to autocomplete of my IDE ^^

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T07:34:38+00:00Added an answer on May 23, 2026 at 7:34 am

    std::string works because your standard library implementation uses small-string-optimization (SSO). That means that the value of the string "something" is copied into the string object itself, without any dynamic memory allocations. Hence you can read it from the other process. For longer strings (try 30 characters) it won’t work.

    std::vector doesn’t work because it’s not allowed to use SSO by standard. It allocates the memory in the address space of the first process, but this memory is not accessible by the other process. The .size() works because it’s stored inside the vector itself, as a member.

    P.S. there are many differences between string and vector. The most important one, and the least mentioned, is that string is not a container from standard’s point of view.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

boost::tuple has a get() member function used like this: tuple<int, string, string> t(5, foo,
Has somebody ported and used Boost on Android? I've found the tool which builds
What is native Linux API used for Boost named_condition class implementation? In Windows, I
I started to write a class which would act much like the std::vector but
I've used boost serialization but this doesn't appear to allow me to generate xml
When the Boost library/headers is used with VC++ 9 compilers (Visual C++ 2008 Express
Can Spirit (part of Boost C++ library) be used to parse out binary data
I hear that tr1::result_of gets used frequently inside of Boost... I'm wondering if there
So, I've been reading through and it appears that the Boost libraries get used
I've used boost::gregorian::date a bit now. I can see that there are the related

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.