Share via


Marshal.AllocHGlobal-Methode: (IntPtr)

 

Veröffentlicht: Oktober 2016

Reserviert Speicher aus dem nicht verwalteten Arbeitsspeicher des Prozesses mithilfe des Zeigers auf die angegebene Anzahl von Bytes.

Namespace:   System.Runtime.InteropServices
Assembly:  mscorlib (in mscorlib.dll)

Syntax

[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

Parameter

  • cb
    Type: System.IntPtr

    Die erforderliche Anzahl der Bytes im Speicher.

Rückgabewert

Type: System.IntPtr

Ein Zeiger auf den neu reservierten Speicher. Dieser Speicher muss unter Verwendung der Marshal.FreeHGlobal-Methode freigegeben werden.

Ausnahmen

Exception Condition
OutOfMemoryException

Es ist nicht genügend Arbeitsspeicher zum Erfüllen der Anforderung vorhanden.

Hinweise

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).

Sicherheit

SecurityCriticalAttribute

requires full trust for the immediate caller. This member cannot be used by partially trusted or transparent code.

Versionsinformationen

Universelle Windows-Plattform
Verfügbar seit 8
.NET Framework
Verfügbar seit 1.1
Portierbare Klassenbibliothek
Unterstützt in: portierbare .NET-Plattformen
Windows Phone
Verfügbar seit 8.1

Siehe auch

AllocCoTaskMem
FreeHGlobal
AllocHGlobal Überladen
Marshal-Klasse
System.Runtime.InteropServices-Namespace

Zurück zum Anfang