c++ - Does the standard guarantee, that std::string::resize will not do reallocate memory, if the new size is less than or equal to as the old one? -


i need make string empty , append chars it. std::string::clear() may realloc std::string::resize(0) realloc? standard's words didn't garentee it.

i think best possible answer "notes" section @ http://en.cppreference.com/w/cpp/string/basic_string/clear.

unlike std::vector::clear, c++ standard not explicitly require capacity unchanged function, existing implementations not change capacity.

and if capacity unchanged, mean no allocation or freeing functions called. that's best can do, short of looking @ each , every implementation care about.


Comments

Popular posts from this blog

linux - xterm copying to CLIPBOARD using copy-selection causes automatic updating of CLIPBOARD upon mouse selection -

qt - Errors in generated MOC files for QT5 from cmake -