My question is regarding the following scenario:
std::string *ps = new std::string();
*ps = aVeryLargeString;
What usually happens from my experience is that aVeryLargeString exceeds the capacity of *ps, so *ps allocates extra memory, keeping the starting position the same. So ps will still point to the new string as the location in memory is the same.
However, what happens if there is not enough contiguous space at that memory location? Does the reallocation move the string to a completely different place, thus invalidating the pointer?
Aucun commentaire:
Enregistrer un commentaire