title: how to get the region size that is reserved in the initial allocation call to VirtualAlloc
body: <p>in msdn doc of VirtualFree </p>
  
  <p><code></p>
  
  <pre><code>BOOL WINAPI VirtualFree(
    _In_  LPVOID lpAddress,
    _In_  SIZE_T dwSize,
    _In_  DWORD dwFreeType
  );
  </code></pre>
  
  <p></code></p>
  
  <p>dwSize [in] 
  The size of the region of memory to be freed, in bytes. </p>
  
  <p>If the dwFreeType parameter is MEM_RELEASE, this parameter must be 0 (zero). The function frees the entire region that is reserved in the initial allocation call to VirtualAlloc.</p>
  
  <p>seem that system can be obtained the entire region size through the address</p>
  
  <p>My question is : 
   how can I do that (to obtained the entire region size through the address)</p>
  
  <p>PS : VirtualQuery API can not do that</p>
  
  <p><code></p>
  
  <pre><code>void* p = VirtualAlloc(null, static_cast&lt;SIZE_T&gt;(_K * 128), MEM_RESERVE, PAGE_NOACCESS);
  p = VirtualAlloc(p, _K * 64, MEM_COMMIT, PAGE_READWRITE);
  MEMORY_BASIC_INFORMATION im;
  VirtualQuery(p, &amp;im, sizeof(im));
  </code></pre>
  
  <p></code></p>
  
  <p>the im.RegionSize is the size of MEM_COMMIT, not the entire region size of first call VirtualAlloc</p>