c++ - std::string capacity size -


is capacity size of string multiple value of 15?

for example: in cases capacity 15

string s1 = "hello";  string s2 = "hi";  string s3 = "hey"; 

or random?

is capacity size of string multiple value of 15?

no; guarantee capacity of std::string s.capacity() >= s.size().

a implementation grow capacity exponentially doubles in size each time reallocation of underlying array required. required std::vector push_back can have amortized constant time complexity, there no such requirement std::string.

in addition, std::string implementation can perform small string optimizations strings smaller number of characters stored in std::string object itself, not in dynamically allocated array. useful because many strings short , dynamic allocation can expensive. small string optimization performed if number of bytes required store string smaller number of bytes required store pointers dynamically allocated buffer.

whether or not particular implementation performs small string optimizations, don't know.


Comments

Popular posts from this blog

apache - Add omitted ? to URLs -

redirect - bbPress Forum - rewrite to wwww.mysite prohibits login -

php - How can I stop spam on my custom forum/blog? -