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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T23:00:51+00:00 2026-05-13T23:00:51+00:00

This is driving me wild with frustration. I am just trying to create a

  • 0

This is driving me wild with frustration. I am just trying to create a shared memory buffer class that uses in shared memory created through Boost.Interprocess where I can read/store data. I wrote the following to test the functionality

#include <boost/interprocess/shared_memory_object.hpp>
#include <boost/interprocess/mapped_region.hpp>
#include <iostream>
using namespace std;
using namespace boost::interprocess;

int main( int argc, char* argv[] ) {
    shared_memory_object::remove( "MyName" );
    // Create a shared memory object
    shared_memory_object shm ( create_only, "MyName", read_write );
    // Set size for the shared memory region
    shm.truncate(1000);
    // Map the whole shared memory in this process
    mapped_region region(shm, read_write);
    // Get pointer to the beginning of the mapped shared memory region
    int* start_ptr;
    start_ptr = static_cast<int*>(region.get_address());

    // Write data into the buffer
    int* write_ptr = start_ptr;
    for( int i= 0; i<10; i++ ) {
        cout << "Write data: " << i << endl;
        memcpy( write_ptr, &i, sizeof(int) );
        write_ptr++;
    }

    // Read data from the buffer
    int* read_ptr = start_ptr;
    int* data;
    for( int i= 0; i<10; i++ ) {
        memcpy( data, read_ptr, sizeof(int) );
        cout << "Read data: " << *data << endl;
        read_ptr++;
    }

    shared_memory_object::remove( "MyName" );
    return 0;
}

When I run this, it writes the data OK, but segfaults on the first memcpy in the read loop. gdb says the following:

Program received signal EXC_BAD_ACCESS, Could not access memory.
Reason: KERN_INVALID_ADDRESS at address: 0x0000000000000000
0x00007fffffe007c5 in __memcpy ()

(gdb) where

#0 0x00007fffffe007c5 in __memcpy ()
#1 0x0000000100000e45 in main (argc=1, argv=0x7fff5fbff9d0) at try.cpp:36

The functionality is so simple, I don’t know what I’m missing. Any help will be much appreciated.

  • 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-13T23:00:52+00:00Added an answer on May 13, 2026 at 11:00 pm

    data isn’t being set to point at anything. (Make sure the program is being compiled with all warnings enabled.) It looks like it shouldn’t be a pointer anyway.

    The second loop should perhaps be:

    int* read_ptr = start_ptr;
    int data;
    for( int i= 0; i<10; i++ ) {
        memcpy( &data, read_ptr, sizeof(int) );
        cout << "Read data: " << data << endl;
        read_ptr++;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is driving me crazy, as it's very easy on gitk (just gitk the/file
This is driving me crazy! I keep crashing with this error. Below is my
I've got a web app that uses a MS SQL Server 2008 database. Recently
I am trying to make a long list of xpath query tests into a
I am trying like below to get the value of a checked radio button
I'm sure I'm contravening some deep dark law of javascript, but I'm not really
Can someone please educate me on why the result is what it is, instead
Despite the other excellent answers here to similar posts, I cannot see the error
If I try and make a facebook like button to like the following url:
I'm using SQLAlchemy 0.6.6 against a Postgres 8.3 DB on Windows 7 an PY

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.