I know that in C++03, technically the std::basic_string
template is not required to have contiguous memory. However, I\'m curious how many implementations exist
Edit: You want to call &buffer[0]
, not buffer.data()
, because []
returns a non-const
reference and does notify the object that its contents can change unexpectedly.
It would be cleaner to do buffer.data()
, but you should worry less about contiguous memory than memory shared between structures. string
implementations can and do expect to be told when an object is being modified. string::data
specifically requires that the program not modify the internal buffer returned.
VERY high chances that some implementation will create one buffer for all strings uninitialized besides having length set to 10 or whatever.
Use a vector
or even an array with new[]
/delete[]
. If you really can't copy the buffer, legally initialize the string to something unique before changing it.