Possible Duplicate:
std::string and its automatic memory resizing
I am just curious, how are strings stored in memory? for example, when I do this:
string testString = "asd";
it allocates 4 bytes, right? a + s + d + \0
.
But later, when I want to assign some new text to this string, it works, but I don't understand how. For example I do this:
testString = "123456789"
Now it should be 10 bytes long. But what if there wasn't space for such string? let's say that fifth+sixth bytes from the beginning of string are taken by some other 2 chars. How does the CPU handles it? It finds completely new position in memory where that string fits?