title: Why should I use my own buffer for getline or similar functions?
body: <p>I was writing a program the other day where I used the <code>getline()</code> function and I realized something that I have never thought of before and haven't been able to find anything about it online.</p>
  
  <p>According to the description of <code>getline</code> from the man page: </p>
  
  <blockquote>
    <p>DESCRIPTION</p>
    
    <p>The <code>getdelim()</code> function reads a line from stream, delimited by the character delimiter.  The <code>getline()</code> function is equivalent to <code>getdelim()</code> with the newline character as the delimiter.  The delimiter character is included as part of the line, unless the end of the file is reached.</p>
    
    <p>The caller may provide a pointer to a malloced buffer for the line in <code>*linep</code>, and the capacity of that buffer in <code>*linecapp</code>.  These functions expand the buffer as needed, as if via <code>realloc()</code>.  If <code>linep</code> points to a <code>NULL</code> pointer, a new buffer will be allocated.  In either case, <code>*linep</code> and <code>*linecapp</code> will be updated accordingly.</p>
  </blockquote>
  
  <p>Normally when I use this function I always malloc my own buffer and pass it into the getline funciton but after reading this I realized that this is not necessary as one will just be created.</p>
  
  <p>My question is: Is there any reason why I should create my own buffer and then pass it into getline as opposed to just passing <code>NULL</code> and letting getline handle the buffer?</p>
  
  <p>The only reason I could think of is if you want to exercise control over the size of the buffer but this doesn't seem right because it says it will resize the buffer as necessary. </p>
  
  <p>When should I use my own buffer and when should I let getline handle the creation of the buffer? </p>