title: Why does libc++'s implementation of std::string take up 3x memory as libstdc++?
body: <p>Consider the following test program:</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;string&gt;
  #include &lt;vector&gt;
  
  int main()
  {
      std::cout &lt;&lt; sizeof(std::string("hi")) &lt;&lt; " ";
      std::string a[10];
      std::cout &lt;&lt; sizeof(a) &lt;&lt; " ";
      std::vector&lt;std::string&gt; v(10);
      std::cout &lt;&lt; sizeof(v) + sizeof(std::string) * v.capacity() &lt;&lt; "\n";
  }
  </code></pre>
  
  <p>Output for <code>libstdc++</code> and <code>libc++</code> respectively are:</p>
  
  <pre><code>8 80 104
  24 240 264
  </code></pre>
  
  <p>As you can see, <code>libc++</code> takes 3 times as much memory for a simple program. How does the implementation differ that causes this memory disparity? Do I need to be concerned and how do I workaround it?</p>