title: Can std::string reallocation invalidate pointer to heap?
body: <p>My question is regarding the following scenario:</p>
  
  <pre><code>std::string *ps = new std::string();
  *ps = aVeryLargeString;
  </code></pre>
  
  <p>What usually happens from my experience is that aVeryLargeString exceeds the capacity of *ps, so *ps allocates extra memory, <em>keeping the starting position the same.</em> So ps will still point to the new string as the location in memory is the same. </p>
  
  <p>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?</p>