If you swap c strings, is there memory swapping?
Suppose we have:
string_class s1("hello");
string_class s2("goodbye");
If the internal representation of string_class is string c, what happens to memory allocation when values ββare replaced? For example, say string_class does allocate char* c_str_s1 = new char[5]
, but char* c_str_s2 = new char[10]
(because, say, after 5, the size is doubled). If we do something like std::swap(c_str_s1, c_str_s2)
, is this the memory allocated for each from the sw line, or the minimum allocation assigned to each?
+3
source to share