title: Can AllocHGlobal allocate more the 2GB of memory?
body: <p>I have resorted to using the Win32 API calls VirtualAlloc/VirtualFree to allocate and release memory blocks greater than 2GB in size.</p>
  
  <p>I should be able to use the AllocHGlobal function from the System.Runtime.InteropServices.Marshal class to do the same.</p>
  
  <p>However, the following code gives an arithmetic overflow exception (note the explicit cast to long which should instance a 64 bit pointer).</p>
  
  <pre><code>
  Dim p As IntPtr = System.Runtime.InteropServices.Marshal.AllocHGlobal(New IntPtr(CLng(3221225472)))
  System.Runtime.InteropServices.Marshal.FreeHGlobal(p)
  </code></pre>
  
  <p>So my question is, Can I use AllocHGlobal to allocate more than 2GB of memory?  If so, how?</p>