title: std::shared_ptr takes lot more memory space than vector
body: <p>I have a voxel structure as:</p>
  
  <pre><code>struct voxel
  {
      unsigned char R, G, B;
      voxel()
      {
          R = G = B = 0;
      }
      //parameteric contructor with parameters
      voxel(unsigned char pR, unsigned char pG, unsigned char pB)
      {
          R = pR; G = pG; B = pB;
      }
  };
  </code></pre>
  
  <p>I have a very large n for number of voxels.</p>
  
  <pre><code>int n = 300 * 300 * 300;
  </code></pre>
  
  <p>Now when i initialize voxels with vector it takes approximately 79 MB in RAM.</p>
  
  <pre><code>std::vector&lt; voxel &gt; vi(n);
  </code></pre>
  
  <p>But it takes more than 2 GB when i initialize it this way using shared_ptr and stack overflows.</p>
  
  <pre><code>std::vector&lt; std::shared_ptr&lt;voxel&gt; &gt; vi(n);
  for (size_t i = 0; i &lt; n; i++)
  {
      vi.push_back(std::shared_ptr&lt;voxel&gt;(new voxel()));
  }
  </code></pre>
  
  <p>What could be the reason for this behavior and how can i avoid it?</p>
  
  <p>Additional Notes:</p>
  
  <pre><code>std::vector&lt; std::shared_ptr&lt;voxel&gt; &gt; vi(n); //statement takes 211 MB alone
  </code></pre>
  
  <p>Update:
  I have also tried with this loop instead of push back but the result is same. I now have a general gist of why is this happening.</p>
  
  <pre><code>for (size_t i = 0; i &lt; n; i++)
      {
          vi[i].reset(new voxel());
          vi[i]-&gt;B = 0;
          vi[i]-&gt;R = 0;
          vi[i]-&gt;G = 0;
      }
  </code></pre>