title: Memory pools and buffers C++
body: <p>I have a few questions about buffers and memory pools i would like to have answered.</p>
  
  <p>Say i have a server, sending and receiving ~50-100+ msg / second. All msgs come in various sizes. How would you go about it to make the best of the memory management here ? My original plan was using fixed sized buffer nodes, and pool them, something like:</p>
  
  <pre><code>struct buffer{
      uint8_t  data[512];
      uint32_t end;
      buffer*  next;
  }
  buffer* b = pool_get_new_buffer();
  </code></pre>
  
  <p>So when a msg is sent, i create one or more buffers depending on the size and link them together. This way i dont have be afraid of fragmentation in the pool it self. (or thats atleast what i think). But on small msg, its a waste of space.</p>
  
  <p>But reading more and more and checking out code on the internet, it looks like nobody uses this approach at all. So what would be a better approach ? Allocating memory from the pool depending on msg size ? </p>
  
  <p><strong>EDIT</strong>:
  So what im after here is maybe a more indept comparison of the different approaches.</p>
  
  <p>If i use the chained buffer approach im guessing i will keep fragmentation at its lowest but on the other hand i would guess that doing memcpy for every buffer in the chain comes at a cost as well. But then again, allocating a large enough buffer and doing a single memcpy must have its downsides as well, even though most people choose this approach anyway.</p>