title: C - shared memory - dynamic array inside shared struct
body: <p>i'm trying to share a struct like this<br>
  example:  </p>
  
  <pre><code>typedef struct {
      int* a;
      int b;
      int c;
  } ex;
  </code></pre>
  
  <p>between processes, the problem is that when I initialize 'a' with a malloc, it becomes private to the heap of the process that do this(or at least i think this is  what happens). Is there any way to create a shared memory (with shmget, shmat) with this struct that works?  </p>
  
  <p>EDIT: I'm working on Linux.<br>
  EDIT: I have a process that initialize the buffer like this:  </p>
  
  <pre><code>key_t key = ftok("gr", 'p');   
  int mid = shmget(key, sizeof(ex), IPC_CREAT | 0666);    
  ex* e = NULL;
  status b_status = init(&amp;e, 8); //init gives initial values to b c and allocate space for 'a' with a malloc
  e = (ex*)shmat(mid, NULL, 0);
  </code></pre>
  
  <p>the other process attaches himself to the shared memory like this:  </p>
  
  <pre><code>key_t key = ftok("gr", 'p');
  int shmid = shmget(key, sizeof(ex), 0);
  ex* e;
  e = (ex*)shmat(shmid, NULL, 0);  
  </code></pre>
  
  <p>and later get an element from a, in this case that in position 1  </p>
  
  <pre><code>int i = get_el(e, 1);
  </code></pre>