title: For what do I need to use VirtualAlloc/VirtualAllocEx?
body: <p>For what do I need to use VirtualAlloc/VirtualAllocEx?</p>
  
  <p>An example, one case that I found - if I allocated 4 GB of virtual memory, then if I do not use all of them, then I do not spend physical memory, and if I resize my array, I <strong>do not need to do new allocating and copying old data</strong> to new array.</p>
  
  <pre><code>struct T_custom_allocator; // which using VirtualAllocEx()
  std::vector&lt;int, T_custom_allocator&gt; vec;
  vec.reserve(4*1024*1024*1024);  // allocated virtual memory (physical memory is not used)
  vec.resize(16384); // allocated 16KB of physical memory
  // ...
  vec.resize(32768); // allocated 32KB of physical memory 
                     // (no need to copy of first 16 KB of data)
  </code></pre>
  
  <p>And if I used standard allocator, I <strong>need to copy of data</strong> when I do resize:</p>
  
  <pre><code>std::vector&lt;int&gt; vec;
  vec.resize(16384); // allocated 16KB of physical memory
  // ...
  vec.resize(32768); // allocated 32KB of physical memory 
                     // and need to copy of first 16 KB of data
  </code></pre>
  
  <p>Or with standatd allocator, I <strong>must spend 4GB</strong> of physical memory:</p>
  
  <pre><code>std::vector&lt;int&gt; vec;
  vec.reserve(4*1024*1024*1024);  // allocated 4GB of physical memory
  vec.resize(16384); // no need to do, except changing a local variable of size
  // ...
  vec.resize(32768); // no need to do, except changing a local variable of size
  </code></pre>
  
  <p>But, why this is better than realloc()?
  <a href="http://www.cplusplus.com/reference/cstdlib/realloc/" rel="noreferrer">http://www.cplusplus.com/reference/cstdlib/realloc/</a></p>
  
  <p>And are there any else cases to use VirtualAlloc[Ex] with benefits?</p>