title: C Programming: malloc and free within a loop
body: <p>I just started out with C and have very little knowledge about performance issues with <code>malloc()</code> and <code>free()</code>. My question is this: if I were to call <code>malloc()</code> followed by <code>free()</code> inside a <code>while</code> loop that loops for, say, 20 iterations, would it run slower compared to calling <code>free()</code> <em>outside</em> the loop?</p>
  
  <p>I am actually using the first method to allocate memory to a buffer, read a variable-length string from a file, perform some string operations, and then clear the buffer after every iteration. If my method results in a lot of overhead then I'd like to ask for a better way for me to achieve the same results.</p>