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