title: Efficient way to read file multiple line one time?
body: <p>I am now trying to handle a large file (several GB), so I am thinking to use multi-thread. The file is multiple lines of data like:</p>
  
  <pre><code>data1 attr1.1 attr1.2 attr1.3
  data2 attr2.1 attr2.2 attr2.3
  data3 attr3.1 attr3.2 attr3.3
  </code></pre>
  
  <p>I am thinking to use one thread read multiple lines first to a buffer1, and then one other thread to handle the data in buffer1 line by line, while the reading thread start to read file to buffer2. Then the handling thread continues when buffer2 is ready, and the reading thread read to buffer1 again.</p>
  
  <p>Now I finished the handler part by using <code>freads</code> for small file (several KB), but I am not sure how to make the buffer contains the complete line instead of splitting part of line at end of the buffer, which is like this:</p>
  
  <pre><code>data1 attr1.1 attr1.2 attr1.3
  data2 attr2.1 att
  </code></pre>
  
  <p>Also, I find that the <code>fgets</code> or <code>ifstream getline</code> can read file line by line, but would it be very costly since it has many IOs?</p>
  
  <p>Now I am struggling to figure out what it the best way to do that? Is there any efficient way to read multiple lines at one time? Any advice is appreciated.</p>