Marshal.AllocHGlobal メソッド
定義
重要
一部の情報は、リリース前に大きく変更される可能性があるプレリリースされた製品に関するものです。 Microsoft は、ここに記載されている情報について、明示または黙示を問わず、一切保証しません。
プロセスのアンマネージ メモリからメモリを割り当てます。
オーバーロード
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 は、クラス内の 2 つのメモリ割り当てメソッドのいずれか 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 は、クラス内の 2 つのメモリ割り当てメソッドのいずれか Marshal です。 (Marshal.AllocCoTaskMem もう一方です。)このメソッドは、Kernel32.dllから Win32 LocalAlloc 関数を公開します。
呼び出しLocalAlloc
時AllocHGlobalにフラグがLMEM_FIXED
渡され、割り当てられたメモリが所定の位置にロックされます。 また、割り当てられたメモリは 0 で満たされません。
コード例については、次をAllocHGlobal参照してくださいMarshal。