System.Runtime.InteropServices.Marshal.AllocCoTaskMem Method

Allocates a block of memory of specified size from the COM task memory allocator.

Syntax

public static IntPtr AllocCoTaskMem (int cb)

Parameters

cb
The size of the block of memory to be allocated.

Returns

An integer representing the address of the block of memory allocated. This memory must be released with Marshal.FreeCoTaskMem(IntPtr).

Remarks

Marshal.AllocCoTaskMem(int) is one of two memory allocation API methods in the System.Runtime.InteropServices.Marshal class. (Marshal.AllocHGlobal(IntPtr) is the other.) The initial memory content returned is undefined, and the allocated memory can be larger than the requested number of bytes. This method exposes the COM tp://go.microsoft.com/fwlink/?LinkId=148626 function, which is referred to as the COM task memory allocator.

Requirements

Namespace: System.Runtime.InteropServices
Assembly: mscorlib (in mscorlib.dll)
Assembly Versions: 1.0.5000.0, 2.0.0.0, 4.0.0.0