string memory pre-allocation

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Jarek

    #1

    string memory pre-allocation

    Hi all!

    As I understand string class, whenever string is expanded (i.e. by +=
    ), the memory is reallocated with new bigger size.
    Is it makes sense ( from perforamance point of view ) to pre-allocate
    some memory for string, i.e.:

    string temp(100,' ');

    temp.clear();


    temp += "a";
    temp += "b";
    ...


    Jarek
  • Tim Love

    #2
    Re: string memory pre-allocation

    Jarek <jarek@poczta.s rv.pl> writes:
    [color=blue]
    >Hi all!
    >
    > As I understand string class, whenever string is expanded (i.e. by +=
    >), the memory is reallocated with new bigger size.[/color]
    Not really. Read about size(), capacity(), and reserve() member functions.

    Comment

    Working...