title: Why use shm_open?
body: <p>What's the advantage of doing: <code>shm_open</code> followed a <code>mmap</code>?<br />
  Why not create a regular file, and then pass that <code>fd</code> to <code>mmap</code>?<br />
  I can't see the advantage of <code>shm_open</code> - these are just references, are they not?</p>
  <p>I've read the man of the whole family. It seems to me, that the &quot;secret&quot; is in the mmaping action - the file &quot;type&quot; seems to be meaningless.</p>
  <p>Any pointers will be good, especially with performance account.<br />
  My context is a (cyclic over-writable) buffer (say 128MB) that will be constantly written to be one process, and constantly dumped from by another.</p>
  <p>As an example: what's wrong with <a href="http://beej.us/guide/bgipc/output/html/multipage/mmap.html" rel="noreferrer">this</a> open/mmap approach.</p>
  <p><strong>EDIT</strong><br />
  To be precise, is one of the following better than the other:</p>
  <pre><code>fd = open(&quot;/dev/shm/myshm.file&quot;, O_CREAT|O_RDWR, S_IRUSR | S_IWUSR);
  mem = mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0);
  </code></pre>
  <p>vs.</p>
  <pre><code>fd = shm_open(&quot;/myshm.file&quot;, O_RDWR|O_CREATE, S_IRUSR | S_IWUSR);
  mem = mmap(...same as before...);
  </code></pre>
  <p>When I created a file with regular <code>open</code> under the <code>/dev/shm</code> fs, and dumped a Gig of garbage to it, my available memory went down by 1G, and my avaiable disk space remained the same.<br />
  What's the difference between the two methods?</p>