Marshal.AllocHGlobal 메서드

정의

프로세스의 관리되지 않는 메모리에서 메모리를 할당합니다.

오버로드

AllocHGlobal(Int32)

지정된 바이트 수를 사용하여 프로세스의 관리되지 않는 메모리에서 메모리를 할당합니다.

AllocHGlobal(IntPtr)

지정된 바이트 수에 대한 포인터를 사용하여 프로세스의 관리되지 않는 메모리에서 메모리를 할당합니다.

AllocHGlobal(Int32)

지정된 바이트 수를 사용하여 프로세스의 관리되지 않는 메모리에서 메모리를 할당합니다.

public:
 static IntPtr AllocHGlobal(int cb);
[System.Security.SecurityCritical]
public static IntPtr AllocHGlobal (int cb);
public static IntPtr AllocHGlobal (int cb);
[<System.Security.SecurityCritical>]
static member AllocHGlobal : int -> nativeint
static member AllocHGlobal : int -> nativeint
Public Shared Function AllocHGlobal (cb As Integer) As IntPtr

매개 변수

cb
Int32

메모리에서 필요한 바이트 수 입니다.

반환

IntPtr

nativeint

새로 할당된 메모리에 대한 포인터입니다. 이 메모리는 FreeHGlobal(IntPtr) 메서드를 사용하여 해제되어야 합니다.

특성

예외

메모리가 부족하여 요청을 만족시킬 수 없습니다.

예제

다음 예제에서는 AllocHGlobal 메서드를 호출하는 방법을 보여 줍니다. 이 코드 예제는에 대해 제공 된 큰 예제의 일부는 Marshal 클래스입니다.

// Demonstrate how to call GlobalAlloc and 
// GlobalFree using the Marshal class.
IntPtr hglobal = Marshal::AllocHGlobal(100);
Marshal::FreeHGlobal(hglobal);
// Demonstrate how to call GlobalAlloc and
// GlobalFree using the Marshal class.
IntPtr hglobal = Marshal.AllocHGlobal(100);
Marshal.FreeHGlobal(hglobal);
' Demonstrate how to call GlobalAlloc and 
' GlobalFree using the Marshal class.
Dim hglobal As IntPtr = Marshal.AllocHGlobal(100)
Marshal.FreeHGlobal(hglobal)

설명

AllocHGlobal 는 클래스의 두 메모리 할당 방법 Marshal 중 하나입니다. (Marshal.AllocCoTaskMem 은)입니다. 이 메서드는 Kernel32.dll Win32 LocalAlloc 함수를 노출합니다.

호출LocalAlloc할 때 AllocHGlobal 플래그를 LMEM_FIXED 전달하여 할당된 메모리가 제자리에 잠깁니다. 또한 할당된 메모리가 0으로 채워지지 않습니다.

추가 정보

적용 대상

AllocHGlobal(IntPtr)

지정된 바이트 수에 대한 포인터를 사용하여 프로세스의 관리되지 않는 메모리에서 메모리를 할당합니다.

public:
 static IntPtr AllocHGlobal(IntPtr cb);
[System.Security.SecurityCritical]
public static IntPtr AllocHGlobal (IntPtr cb);
public static IntPtr AllocHGlobal (IntPtr cb);
[<System.Security.SecurityCritical>]
static member AllocHGlobal : nativeint -> nativeint
static member AllocHGlobal : nativeint -> nativeint
Public Shared Function AllocHGlobal (cb As IntPtr) As IntPtr

매개 변수

cb
IntPtr

nativeint

메모리에서 필요한 바이트 수 입니다.

반환

IntPtr

nativeint

새로 할당된 메모리에 대한 포인터입니다. 이 메모리는 FreeHGlobal(IntPtr) 메서드를 사용하여 해제되어야 합니다.

특성

예외

메모리가 부족하여 요청을 만족시킬 수 없습니다.

설명

AllocHGlobal 는 클래스의 두 메모리 할당 방법 Marshal 중 하나입니다. (Marshal.AllocCoTaskMem 은)입니다. 이 메서드는 Kernel32.dll Win32 LocalAlloc 함수를 노출합니다.

호출LocalAlloc할 때 AllocHGlobal 플래그를 LMEM_FIXED 전달하여 할당된 메모리가 제자리에 잠깁니다. 또한 할당된 메모리가 0으로 채워지지 않습니다.

예제 코드는 MarshalAllocHGlobal를 참조하십시오.

추가 정보

적용 대상