title: Constructing data pools for components
body: <p>I'm running Windows 7 with a Core Duo.  I've been using Codeblocks for a while now, which I think I have using GNU compiler.</p>
  
  <p>I have (or will have) many component classes that inherit from the abstract class <code>Component</code>.  I need help establishing a system to house memory pools for an undetermined amount of component types, each with an undetermined amount of components.  Maybe for the sake of argument the latter is fixed, I can figure out how to change size when abolutely necessary.  </p>
  
  <p>Also, conveniently so, each component type has an ID (<code>unsigned short</code>) from 0 to whatever with no holes.  Yay!  </p>
  
  <p>So, assuming I have some managing clas to keep track of array sizes and things, would something like this work?</p>
  
  <pre><code>class Component {};
  
  class FooComponent: public Component {};
  class BarComponent: public Component {};
  .
  .
  .
  
  std::vector&lt;Component*&gt; pool_list;
  
  // returns pointer to beginning of pool
  Component* foo_pool = MethodToCreateComponentPool(/* Params */)
  Component* bar_pool = MethodToCreateComponentPool(/* Params */)
  
  pool_list.push_back(foo_pool);
  pool_list.push_back(bar_pool);
  </code></pre>
  
  <p>Maybe put <code>sizeof(FooComponent)</code> in for Params.   </p>
  
  <p>Then (Where I really start to not know what to do) inside the function do an <code>malloc( START_COUNT * component_size)</code></p>
  
  <p>I have no experience allocating memory like this.  I can easily set up something like  </p>
  
  <p><code>vector&lt; vector&lt;Component*&gt;* &gt;</code> or<br>
  <code>map&lt;unsigned short, vector&lt;Component*&gt; &gt;</code> </p>
  
  <p>but it (is ugly for one) doesn't give me contiguous pools.  I need cache friendly :)</p>
  
  <p>Ideas?  Patterns?  Idioms?  Help?</p>