title: C++ virtual function table memory cost
body: <p>Consider:</p>
  
  <pre><code>class A
  {
      public:
          virtual void update() = 0;
  }
  
  class B : public A
  {
      public:
          void update() { /* stuff goes in here... */ }
  
      private:
          double a, b, c;
  }
  
  class C { 
    // Same kind of thing as B, but with different update function/data members
  }
  </code></pre>
  
  <p>I'm now doing:</p>
  
  <pre><code>A * array = new A[1000];
  array[0] = new B();
  array[1] = new C();
  //etc., etc.
  </code></pre>
  
  <p>If i call <code>sizeof(B)</code>, the size returned is the size required by the 3 double members, plus some overhead required for the virtual function pointer table. Now, back to my code, it turns out that 'sizeof(myclass)' is 32; that is, I am using 24 bytes for my data members, and 8 bytes for the virtual function table (4 virtual functions). My question is: is there any way I can streamline this? My program will eventually use a heck of a lot of memory, and I don't like the sound of 25% of it being eaten by virtual functions pointers.</p>