title: reading selected lines of file using mmap
body: <p>I posted one <a href="https://stackoverflow.com/questions/53552739/how-to-move-file-pointer-to-next-line-without-parsing-current-line?noredirect=1#comment93978110_53552739">question</a>, which was related to faster reading of a file, by skipping specific lines but that does not seem to go well with standard c++ api's.</p>
  
  <p>I researched more and got to know what memory mapped files could come handy for these kinds of cases. Details about memory mapped files are <a href="https://www.youtube.com/watch?v=m7E9piHcfr4" rel="nofollow noreferrer">here</a>.</p>
  
  <p>All in all,</p>
  
  <p>Suppose, the file(file.txt) is like this:</p>
  
  <pre><code>A quick brown fox 
  // Blah blah
  // Blah blah
  jumps over the little lazy dog
  </code></pre>
  
  <p>And then in code, opened file, Read that as memory mapped file and then iterate over the contents of the char* pointer, skipping the file pointers itself. Wanted to give it a try before reaching to an conclusion on it. Skeleton of my code looks like this:</p>
  
  <pre><code>struct stat filestat;
  FILE *file = fopen("file.txt", "r");
  if (-1 == fstat(fileno(file), &amp;filestat)) {
    std::cout &lt;&lt; "FAILED with fstat" &lt;&lt; std::endl;
    return FALSE;
  } else {
    char* data = (char*)mmap(0, filestat.st_size, PROT_READ, MAP_PRIVATE, fileno(file), 0);
    if (data == 0) {
      std::cout &lt;&lt; "FAILED " &lt;&lt; std::endl;
      return FALSE;
    }
    // Filter out 'data'
    // for (unsigned int i = 0; i &lt; filestat.st_size; ++i) {
    //   Do something here..
    // }
  
    munmap(data, filestat.st_size);
    return TRUE;
  }   
  </code></pre>
  
  <p>In this case, I would want to capture lines which does not start with //. Since this file(file.txt) is already memory mapped, I could go over the data pointer and filter out the lines. Am I correct in doing so?</p>
  
  <p>If so, what is the efficient way to parse the lines?</p>