This documentation is archived and is not being maintained.

IHostMemoryManager::VirtualAlloc Method

Serves as a logical wrapper for the corresponding Win32 function. The Win32 implementation of VirtualAlloc reserves or commits a region of pages in the virtual address space of the calling process.

HRESULT VirtualAlloc (
    [in]  void*   pAddress,
    [in]  SIZE_T  dwSize,
    [in]  DWORD   flAllocationType,
    [in]  DWORD   flProtect,
    [in]  EMemoryCriticalLevel dwCriticalLevel,
    [out] void**  ppMem



[in] A pointer to the starting address of the region to allocate.


[in] The size, in bytes, of the region.


[in] The type of memory allocation.


[in] Memory protection for the region of pages to be allocated.


[in] An EMemoryCriticalLevel Enumeration value that indicates the impact of an allocation failure.


[out] Pointer to the starting address of the allocated memory, or null if the request could not be satisfied.

HRESULT Description


VirtualAlloc returned successfully.


The common language runtime (CLR) has not been loaded into a process, or the CLR is in a state in which it cannot run managed code or process the call successfully.


The call timed out.


The caller does not own the lock.


An event was canceled while a blocked thread or fiber was waiting on it.


An unknown catastrophic failure occurred. When a method returns E_FAIL, the CLR is no longer usable within the process. Subsequent calls to hosting methods return HOST_E_CLRNOTAVAILABLE.


Not enough memory was available to complete the allocation request

You reserve a region in the address space of your process by calling VirtualAlloc. The pAddress parameter contains the beginning address of the memory block you want. This parameter is typically set to null. The operating system keeps a record of free address ranges available to your process. A pAddress value of null instructs the system to reserve the region wherever it sees fit. Alternatively, you can provide a specific starting address for the memory block. In both cases, the output parameter ppMem is returned as a pointer to the allocated memory. The function itself returns an HRESULT value.

The Win32 VirtualAlloc function does not have a ppMem parameter, and returns the pointer to the allocated memory instead. For more information, see the Windows Platform documentation.

Platforms: Windows 2000, Windows XP, Windows Server 2003 family

Header: MSCorEE.idl

Library: Included as a resource in MSCorEE.dll

.NET Framework Version: 2.0