title: One large malloc versus multiple smaller reallocs
body: <p>Sorry if this has been asked before, I haven't been able to find just what I am looking for.</p>
  
  <p>I am reading fields from a list and writing them to a block of memory. I could</p>
  
  <ul>
  <li>Walk the whole list, find the total needed size, do one <code>malloc</code> and THEN walk the list again and copy each field;</li>
  <li>Walk the whole list and <code>realloc</code> the block of memory as I write the values;</li>
  </ul>
  
  <p>Right now the first seems the most efficient to me (smallest number of calls). What are the pros and cons of either approach ?</p>
  
  <p>Thank you for your time.</p>