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

  • Home
  • SEARCH
  • 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 8593881
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T00:05:15+00:00 2026-06-12T00:05:15+00:00

Due to policy where I work, I am unable to use a version of

  • 0

Due to policy where I work, I am unable to use a version of Boost newer than 1.33.1 and unable to use a version of GCC newer than 4.1.2. Yes, it’s garbage, but there is nothing I can do about it. Boost 1.33.1 does not contain the interprocess library.

That said, one of my projects requires placing an std::map (or more likely an std::unordered_map) in to shared memory. It is only written/modified ONE TIME when the process loads by a single process (the “server”) and read by numerous other processes. I haven’t done shared memory IPC before so this is fairly new territory for me. I took a look at shmget() but it would appear that I can’t continually use the same shared memory key for allocation (as I assume would be needed with STL container allocators).

Are there any other NON-BOOST STL allocators that use shared memory?

EDIT: This has been done before. Dr. Dobbs had an article on how to do this exactly back in 2003, and I started to use it as a reference. However, the code listings are incomplete and links to them redirect to the main site.

EDIT EDIT: The only reason I don’t just re-write Boost.Interprocess is because of the amount of code involved. I was just wondering if there was something relatively short and concise specifically for POSIX shared memory that I could re-write from scratch since data transfers between networks are also subject to a multi-day approval process…

  • 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-06-12T00:05:16+00:00Added an answer on June 12, 2026 at 12:05 am

    Pointers do not work in shared memory unless you cannot pin down the shared memory at a fixed address (consistent in all processes). As such, you need specific classes that will either be contiguous (no pointer), or have an offset (and not a pointer) into the memory area in which the shared memory is mapped.

    We are using shared memory at work in a pretty similar situation: one process computes a set of data, places it in shared memory, and then signal the other processes that they may map the memory into their own address space; the memory is never changed afterwards.

    The way we go about it is having POD structures (*) (some including char xxx[N]; attributes for string storage). If you can actually limit your strings, you are golden. And as far as map goes: it’s inefficient for read-only storage => a sorted array performs better (hurray for memory locality). So I would advise going at it so:

    struct Key {
        enum { Size = 318 };
        char value[Size];
    };
    
    struct Value {
        enum { Size = 412 };
        enum K { Int, Long, String };
        K kind;
        union { int i; long l; char string[Size]; } value;
    };
    

    And then simply have an array of std::pair<Key, Value> that you sort (std::sort) and over which you use std::lower_bound for searches. You’ll need to write a comparison operator for key, obviously:

    bool operator<(Key const& left, Key const& right) {
        return memcmp(left.value, right.value, Key::Size) < 0;
    }
    

    And I agree that the enum + union trick is less appealing (interface wise) than a boost variant… it’s up to you to make the interface better.

    (*) Actually, a pure POD is not necessary. It’s perfectly okay to have private attributes, constructors and copy constructors for example. All that is needed is to avoid indirection (pointers).

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

Sidebar

Related Questions

Due to the Content Security Policy of manifest version 2, I can't add a
Due to politics at the very large finanial institution for which I work, I
I am running Xcode 4.2 on OS X 10.6.8. Due to corporate policy, I
The cuda profiler manual states that due to the more relaxed coalescing policy, the
(I see several questions related to my problem but none of the solutions work
Due to the change in CSRF-policy for AJAX requests since Django 1.2.5, all implementations
Since I was to use a new method for 'getcustomers' the app doesn't work.
The first issue that I'd like to highlight is that due to same-origin policy,
From what I understand, due to the same origin policy enforcement in current browsers,
Due to a recent policy change on facebook I now need to know the

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.