Método Marshal.AllocHGlobal (IntPtr)
Publicado: octubre de 2016
Asigna memoria de la memoria no administrada del proceso utilizando el puntero al número especificado de bytes.
Espacio de nombres: System.Runtime.InteropServices
Ensamblado: mscorlib (en mscorlib.dll)
Sintaxis
[SecurityCriticalAttribute]
public static IntPtr AllocHGlobal(
IntPtr cb
)
public:
[SecurityCriticalAttribute]
static IntPtr AllocHGlobal(
IntPtr cb
)
[<SecurityCriticalAttribute>]
static member AllocHGlobal :
cb:nativeint -> nativeint
<SecurityCriticalAttribute>
Public Shared Function AllocHGlobal (
cb As IntPtr
) As IntPtr
Parámetros
cb
Type: System.IntPtrNúmero necesario de bytes en memoria.
Valor devuelto
Type: System.IntPtr
Puntero a la memoria recién asignada. Debe liberarse esta memoria con el método Marshal.FreeHGlobal.
Excepciones
Exception | Condition |
---|---|
OutOfMemoryException | No hay memoria suficiente para satisfacer la solicitud. |
Comentarios
AllocHGlobal is one of two memory allocation methods in the Marshal class. (Marshal.AllocCoTaskMem is the other.) This method exposes the Win32 LocalAlloc function from Kernel32.dll.
When M:System.Runtime.InteropServices.Marshal.AllocHGlobal(System.Int32) calls LocalAlloc, it passes a LMEM_FIXED flag, which causes the allocated memory to be locked in place. Also, the allocated memory is not zero-filled.
For example code, see T:System.Runtime.InteropServices.Marshal and M:System.Runtime.InteropServices.Marshal.AllocHGlobal(System.Int32).
Seguridad
requires full trust for the immediate caller. This member cannot be used by partially trusted or transparent code.
Información de versión
Plataforma universal de Windows
Disponible desde 8
.NET Framework
Disponible desde 1.1
Biblioteca de clases portable
Se admite en: plataformas portátiles de .NET
Windows Phone
Disponible desde 8.1
Ver también
AllocCoTaskMem
FreeHGlobal
AllocHGlobal Sobrecarga
Clase Marshal
Espacio de nombres System.Runtime.InteropServices
Volver al principio