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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T21:57:29+00:00 2026-06-17T21:57:29+00:00

I am working with shared memory and hence I need to attach some portion

  • 0

I am working with shared memory and hence I need to attach some portion of the memory to some other process.
I am trying to attach to a contiguous sequence, but this does not seem to work after the integer and the float arrays.
Here NUMBER_OF_DATA=5

int shmid=shmget(key,size,0777|IPC_CREAT);
  int *a=(int *)shmat(shmid,0,0);
  float *b=(float *)(a+NUMBER_OF_DATA);
  char *array1[20];
array1[0]=(char *)(b+NUMBER_OF_DATA);
  char *array2[20];
array2[0]=(char *)(array1+(20*NUMBER_OF_DATA));
  for(i=0;i<NUMBER_OF_DATA;i++)
    {
      a[i]=roll_no[i];
      b[i]=cgpa[i];
      array1[i]=firstname[i];
      array2[i]=lastname[i];
    printf("%p %p %p %p\n",&a[i],&b[i],&array1[i],&array2[i]);
    }

When I print the addresses, I get

0xb777d000 0xb777d014 0xbfd480a0 0xbfd480f0
0xb777d004 0xb777d018 0xbfd480a4 0xbfd480f4
0xb777d008 0xb777d01c 0xbfd480a8 0xbfd480f8
0xb777d00c 0xb777d020 0xbfd480ac 0xbfd480fc
0xb777d010 0xb777d024 0xbfd480b0 0xbfd48100

which is not continuous after the arrays a and b. Why is this so? What is the solution?

  • 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-17T21:57:31+00:00Added an answer on June 17, 2026 at 9:57 pm

    You’re only initializing the first field of array1 and array2, the rest is uninitialized. You seem to have confused something, but I’m not sure what you exact intention is here.

    If you want the two arrays to be char *s, it’s simple, do it like you did it for the ints and floats.

    However, if you really want something like a char*[], you need to store not just the values, but also the pointers to the values in the shared memory segment.

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

Sidebar

Related Questions

I'm trying hard for some hours and didn't manage to get this working. I
I was working on shared memory and this question came in my mind so
I have two process and a shared memory zone, my workflow is like this.
I am aware of the basics of shared memory and inter process communication, but
I've got Drupal working on a shared host, and I uploaded some modules from
I'm working on a program which uses shared memory. Multiple instances of said program
I would really love some debugging help in this one. I've been working on
I'm trying to use shared memory to cache things with OpenACC. Basically what I'm
I am working on a university assignment, based largely around IPC and shared memory.
Working with shared memory for the first time, my project is to have readers

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.