title: Fastest way of reading from socket and converting bytes C++
body: <p>I'm wondering which is the fastest way of implementing this kind of algorithm in <code>C++</code>:
  I have a source of data that comes over <code>TCP/IP</code> so I read all data from a single socket. I have a flow of bytes that represent and integer of 4 bytes. So the two alternative are:</p>
  
  <ol>
  <li><p>read all bytes until the end(saving them into a very big array of <code>unsigned char</code>) and then convert them all . Pro: I read "only one" time from the socket(I know that <code>read()</code> function reads as mush as it can but lets say that this always happens). Cons: save all bytes into an array but in this way I have to pay the cost of looping over the array, where I saved the bytes, loosing time in memory accesses.</p></li>
  <li><p>read 4 bytes at a time and convert just them. Pro: no memory accesses because I do not save all bytes into a very big array but just in a small array of 4 bytes. Cons: I have to call <code>read(sockfd,buff,4)</code> too many times.</p></li>
  </ol>
  
  <p>What do you think is the best way in terms of performance on your opinion and experience?</p>