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 8311493
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T19:50:00+00:00 2026-06-08T19:50:00+00:00

I am trying to share an unordered map(hash map) but it is ending up

  • 0

I am trying to share an unordered map(hash map) but it is ending up with the Floating point exception at the line where it tries to insert the data in the map.

Could someone please help in understanding where I am going wrong?

#include <iostream>
#include <string>
#include <unordered_map>

#include <sys/ipc.h>
#include <sys/shm.h>
int main ()
{
    std::unordered_map<std::string,double> *tmp;

    key_t key = 5678;
    int shmid = shmget(key, 1000, IPC_CREAT | IPC_EXCL | 644);
    if(shmid == -1){
        std::cerr << "Failed to create the shared segment." << std::endl;
        exit(-1);
    }

    void *addr = shmat(shmid, NULL, 0);
    if(addr == (void*)-1){
        std::cerr << "Failed to attach the segment to the process." << std::endl;
        exit(-1);
    }

    tmp = static_cast< std::unordered_map<std::string,double>* >(addr);
    tmp->insert (std::pair<std::string,double>("abc",1.2));

    shmdt(addr);
    return 0;
}

Thanks.

  • 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-08T19:50:02+00:00Added an answer on June 8, 2026 at 7:50 pm

    In general, you can’t share complex structures between processes. In particular, pointers to objects in the virtual address space of one process won’t be valid in another, and most container implementations will involve pointers.

    You could look at the Boost.Interprocess library which contains various containers and allocators suitable for sharing; in particular, their version of unordered_map can be placed in shared memory, as long as you use their shared memory allocator, so you might simply be able to use that as a replacement for std::unordered_map (although you’d still need a replacement for std::string as the key).

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

Sidebar

Related Questions

Im trying to download share data from a stock exchange using python. The problem
I'm trying to make some social share buttons at my site, but the urls
Ii'm trying to share a Google Spreadsheet using C#. Because the Google Data 3.0
I'm trying to share data between various viewControllers, I'm using a property declared in
Im just trying to share an integer between two processes, but the memory segment
I am trying to brand share point. I have created a mastepage in the
I am trying to share my app (link having data and metatags) with the
I am trying to share a multi-dimensional hash over multiple threads. This hash holds
I wrote two different custom Ant tasks. They are trying to share data through
I'm following the James Brannan tutorial's, and im trying to share data between some

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.