3

in c++98, the memory of std::string(c++11 required it is contiguous) may not a contiguous storage, what about boost::container::string?Is it promise the memory is contiguous?

If it is contiguous, it could work with the legacy api more naturally.

boost::container::string str("some data\0");    
old_api(&str[0]);

don't need to copy it to vector again

boost::container::string str("some data\0");
std::vector<char> buffer(str.begin(), str.end());

old_api(&str[0]);

Thanks

Community
  • 1
  • 1
StereoMatching
  • 4,971
  • 6
  • 38
  • 70

1 Answers1

3

Yes, boost::containter::string memory is contiguous.

And unless you use some funky allocators with non plain reference, const_refeference and pointer types, any boost::container::basic_string specialization has contiguous memory.

Look at string's data() method: it guarantees (unconditional) constant time and that data()+i == &operator[](i) for each i in [0,size()].

seb
  • 326
  • 1
  • 5