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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T08:52:27+00:00 2026-05-16T08:52:27+00:00

I have a very simple class that opens a file and creates a memory

  • 0

I have a very simple class that opens a file and creates a memory mapped file.

The region is mapped to the member variable called data_ which is defined as unsigned char* data_;

The memory map part looks like this:

// Create memory mapped file
unsigned char* data_ = (unsigned char*)mmap(NULL, 1024, 
                           PROT_READ | PROT_WRITE, MAP_SHARED, fd_, 0);

if (block_data_ == MAP_FAILED) {
    throw Exception(std::string("mmap: ") + strerror(errno));
}

Now I can read and write to the file by simply writing to the data_ variable (up to the size 1024.

But, the intention is not to do it this way. I have a function that returns me a pointer to data_.
When I simply create the block it works fine all the way up until I try to write to the data OUTSIDE of the class. That’s when I get a SIGSEGV.

How do I get around that?

  • 1 1 Answer
  • 2 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-16T08:52:28+00:00Added an answer on May 16, 2026 at 8:52 am

    I am not fully sure what you mean that you have done so far. In the code you posted, it appears as if you assign the return-value of mmap to a local variable data_ instead of the member-variable data_. Is this just the currently “working” version (that isn’t intended to use the member-variable), or is it an error?

    Are you sure you want to return a pointer to data_? Isn’t it data_ itself that you want to return? Returning a pointer to data_ sounds like something you might do if you want to change what it points to, but if data_ already points to the mmapped area, doing that sounds wrong.

    Using the mmapped memory outside of the class should be no different from using it inside the class, so it sounds to me like you might have done something wrong either when assigning or returning the member-variable data_.

    In the code you posted, you also check block_data instead of data_ for error.

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

Sidebar

Related Questions

So I have a very simple class that has a method called getThumbUrl() but
Let's say I have a very simple PrototypeJS class that looks like this: var
i'm missing something fundamental here. i have a very simple custom class that draws
I have a class that uses org.apache.ant and the class is very simple, it's
I have a very simple class that I'm trying to serialize: [ProtoContract] public class
I have a very simple class with some char* members. Is strcat the best
I have this very simple C++ class: class Tree { public: Node *head; };
I have a very simple activity just to show the preference fragment: public class
I have a very simple scenario, using NHibernate: one abstract base class animal; two
I have a very simple code: package mygame; public class RunGame { public static

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.