title: boost streambuf consume and commit, what is it
body: <p>I can't seem to find a good explanation of what consume() and commit() really means, actually I don't understand streambuf at all.</p>
  
  <p>My understanding is that a streambuf is just a character array. But why is that in the documentation, </p>
  
  <pre><code>basic_streambuf::data
  Get a list of buffers that represents the input sequence.
  </code></pre>
  
  <p>so actually there are many buffers? And what is the 'input sequence' and the 'output sequence'? Are these another two buffers?</p>
  
  <p>What does the following code really do?</p>
  
  <pre><code>streambuf b;
  size_t size;
  size = read( socket, b.prepare( 1024 ) ); 
  b.commit( size );
  size = write( socket, b.data() );
  b.consume( size );
  </code></pre>
  
  <p>when I call b.prepare(), does it allocate a new buffer for the read() to put data? Then when is the data transferred from that buffer to the underlying streambuf buffer? I thought it was the commit(), but</p>
  
  <pre><code>basic_streambuf::commit
  Move characters from the output sequence to the input sequence.
  </code></pre>
  
  <p>so it seems that commit actually moves the data from the 'output sequence' to 'input sequence' without ever mentioning the underlying buffer used to store data!</p>