Does std::string use string interning?
<p>I'm especially interested of windows, mingw.</p>

<p>Thanks.</p>

<p>Update:
First, I thought everyone is familiar with string interning.
<a href="http://en.wikipedia.org/wiki/String_interning" rel="nofollow">http://en.wikipedia.org/wiki/String_interning</a></p>

<p>Second, my problem is in detail:
I knocked up a string class for practice. Nothing fancy you know, i just store the size and a char * in a class.</p>

<p>I use memcpy for the assignment.</p>

<p>When i do this to measure the assignment speed of std::string and my string class:</p>

<pre><code>string test1 = "  65 kb text ", test2;
for(int i=0; i&lt;1000000; i++)
   {
   test2 = test1;
   }

mystring test3 = "65 kb text", test4;
for (int i=0; i&lt;1000000; i++)
   {
   test4 = test3
   }
</code></pre>

<p>The std::string is a winner by a large margin. I do not do anything in the assignment operator (in my class) but copy with memcpy. I do not even create a new array with the "new" operator, cause i check for size equality, and only request new if needed. How come?</p>

<p>For small strings, there is no problem. I cant see how can std::string assign values faster than memcpy, i bet it uses it too in the background, or something similar, so that's why i asked interning.</p>

<p>Update2:
by modifying the loops with a single character assignment like this: test2[15] = 78, I avoided the effect of copy-on-write of std::string. Now both codes takes exactly the same time (okay, there is an 1-2% difference, but that is negligible). So if I am not entirely mistaken, the mingw std::string must use COW.</p>

<p>Thank you all for your help.</p>
