title: Can we insert element at the end of an array without copying all it's content?
body: <p>I'm trying to reproduce the behavior of a <code>std::vector</code> in C, and I have something on my mind: a vector has a contiguously allocated memory, which means that when you add an element at the end it does not copy all the array to another block of memory but instead allocates just another element at the end, which increases performance, but in C I can't figure out a way to reproduce that behavior, the only way I can find to add an element at the end is by doing this:</p>
  <pre><code>void *new_array;
  size_t new_size = old_size + size_type;
  new_array = (char*)malloc(size_type * new_size);
  memcpy(new_array, old_array, old_size * size_type);
  memcpy(new_array, new_value, size_type);
  </code></pre>
  <p>and I'm pretty sure that a <code>std::vector</code> doesn't proceed like that, is it possible to reproduce it without allocating a big block of memory before ?</p>