title: Using boost::iostreams::mapped_file
body: <p>I am very new to the memory mapping and trying to understand memory mapped files to use them in my project(linux based).
  My requirement is to write &amp; then read from memory mapped files.
  I wrote a sample program which only writes and it works fine but i have a few very basic doubts as i do not understand this funda of memory mapping properly.</p>
  
  <pre><code>#include &lt;unordered_map&gt;
  #include &lt;boost/iostreams/device/mapped_file.hpp&gt;
  using namespace boost::interprocess;
  using namespace std;
  typedef unordered_map&lt;int, string&gt; work;
  int main()
  {
          boost::iostreams::mapped_file_params  params;
          params.path = "map.dat";
          params.new_file_size = 100;
          params.mode = (std::ios_base::out | std::ios_base::in);
          boost::iostreams::mapped_file  mf;
          mf.open(params);
          work w1;
          w1[0] = "abcd";
          w1[1] = "bcde";
          w1[2] = "cdef";
  
          work* w = static_cast&lt;work*&gt;((void*)mf.data());
          *w = w1;
          mf.close();
          return 0;
  }
  </code></pre>
  
  <p>I have a few questions here:</p>
  
  <ol>
  <li><p>When i do this : mf.open(params) , i see that a file is created on disk with size 100.
  Now when i write to it i.e *w = w1, the contents of the file on disk changes.
  Does this mean that i am not using the RAM at all and i am writing straight into the<br>
  disk?</p></li>
  <li><p>When i do mf.size(), it always give me the size which i gave as the input for creating 
  the actual file. How can i find out the size of the data that i actually wrote into the<br>
  memory mapped file?</p></li>
  <li><p>Also if i give params.new_file_size = 10GB, the file of that size gets created on the<br>
  disk but it does not take up any disk space.Confirmed by using df cmd.  Why so?
  -rwx------. 1 root root 10000000000 Apr 29 14:26 map.dat</p></li>
  <li><p>I read that close file frees the mapping. Does this mean that after close i lose all the 
  data that i wrote? But this is not true as i have the working code where i close and 
  then open the file again and read it correctly.</p></li>
  <li><p>How to delete the memory mapped files created after use? By using rm -rf cmd/linux apis?</p></li>
  </ol>