title: Using mmap() instead of malloc()
body: <p>I am trying to complete an exercise that is done with system calls and need to allocate memory for a struct *. My code is:</p>
  
  <pre><code>myStruct * entry = (myStruct *)mmap(0, SIZEOF(myStruct), PROT_READ|PROT_WRITE,
  MAP_ANONYMOUS, -1, 0);
  </code></pre>
  
  <p>To clarify, I cannot use <code>malloc()</code> but can use <code>mmap()</code>. I was having no issues with this on Windows in Netbeans, now however I'm compiling and running from command line on Ubuntu I am getting "Segmentation Fault" each time I try to access it.</p>
  
  <p>Is there a reason why it will work on one and not the other, and is <code>mmap()</code> a valid way of allocating memory in this fashion? My worry was I was going to be allocating big chunks of memory for each <code>mmap()</code> call initially, now I just cannot get it to run.</p>
  
  <p>Additionally, the error returned my mmap is 22 - Invalid Argument (I did some troubleshooting while writing the question so the error check isn't in the above code). Address is 0, the custom <code>SIZEOF()</code> function works in other mmap arguments, I am using <code>MAP_ANONYMOUS</code> so the <code>fd</code> and <code>offset</code>parameters must -1 and 0 respectively.</p>
  
  <p>Is there something wrong with the <code>PROT_READ|PROT_WRITE</code> sections?</p>