Question: Wrote the following code snippet to find the how many more bytes of memory will each string-append action add to the string. 

```
#include <iostream>
#include <string>
#include <unordered_map>
#include <sys/time.h>
#include <arpa/inet.h>

using namespace std;
typedef unsigned short uint16;
typedef unsigned int uint;

int main (int argc, char *argv[]) {
    const char *p = NULL;
    string s = "";
    for (int i=0; i<1050; i++) {
        s += "a";
        if (s.c_str() != p) {
            printf("%5d\n", i);
            p = s.c_str();
        }
    }
    return 0;
}

```

The output is 

```
    0
    1
    2
    4
    8
   16
   32
   64
  128
  256
  512
 1024

```

So the result quite clearly shows it double the storages of the string each time (at minimum). 

The question is, how to add use specified space (say, 2000 bytes) to an existing string so that one can do many string append without trigger a free/malloc.

Thanks.

Answer: 
You can do that by using the `reserve()` member function.
Note that it may not allocate the exact amount of storage you ask for (you may get more) but you'll get *at least* what you ask for in a single allocation.
Read the documentation!

**This is what [`std::string::reserve`](http://en.cppreference.com/w/cpp/string/basic_string/reserve) is for.**