Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Default capacity of std::string?

When I create a std::string using the default constructor, is ANY memory allocated on the heap? I'm hoping the answer does not depend on the implementation and is standardized. Consider the following:

std::string myString;
like image 880
void.pointer Avatar asked Jan 31 '12 00:01

void.pointer


1 Answers

Unfortunately, the answer is no according to N3290.

Table 63 Page 643 says:

  • data() a non-null pointer that is copyable and can have 0 added to it
  • size() 0
  • capacity() an unspecified value

The table is identical for C++03.

like image 122
pmr Avatar answered Sep 19 '22 23:09

pmr