title: std::string implementation in GCC and its memory overhead for short strings
body: <p>I am currently working on an application for a low-memory platform that requires an std::set of many short strings (>100,000 strings of 4-16 characters each). I recently transitioned this set from std::string to const char * to save memory and I was wondering whether I was really avoiding all that much overhead per string.</p>
  
  <p>I tried using the following:</p>
  
  <pre><code>std::string sizeTest = "testString";
  std::cout &lt;&lt; sizeof(sizeTest) &lt;&lt; " bytes";
  </code></pre>
  
  <p>But it just gave me an output of 4 bytes, indicating that the string contains a pointer. I'm well aware that strings store their data in a char * internally, but I thought the string class would have additional overhead.</p>
  
  <p>Does the GCC implementation of std::string incur more overhead than sizeof(std::string) would indicate? More importantly, is it significant over this size of data set?</p>
  
  <p>Here are the sizes of relevant types on my platform (it is 32-bit and has 8 bits per byte):</p>
  
  <p>char: 1 bytes<br>
  void *: 4 bytes<br>
  char *: 4 bytes<br>
  std::string: 4 bytes  </p>