title: Allocate from buffer in C
body: <p>I am building a simple particle system and want to use a single array buffer of structs to manage my particles.  That said, I can't find a C function that allows me to malloc() and free() from an arbitrary buffer.  Here is some pseudocode to show my intent:</p>
  
  <pre><code>Particle* particles = (Particle*) malloc( sizeof(Particle) * numParticles );
  Particle* firstParticle = &lt;buffer_alloc&gt;( particles );
  initialize_particle( firstParticle );
  // ... Some more stuff
  if (firstParticle-&gt;life &lt; 0)
      &lt;buffer_free&gt;( firstParticle );
  
  // @ program's end
  free(particles);
  </code></pre>
  
  <p>Where <code>&lt;buffer_alloc&gt;</code> and <code>&lt;buffer_free&gt;</code> are functions that allocate and free memory chunks from arbitrary pointers (possibly with additional metadata such as buffer length, etc.).  Do such functions exist and/or is there a better way to do this?  Thank you!</p>