System.Runtime.InteropServices.Marshal.ReAllocHGlobal Method

Resizes a block of memory previously allocated with Marshal.AllocHGlobal(IntPtr).

Syntax

public static IntPtr ReAllocHGlobal (IntPtr pv, IntPtr cb)

Parameters

pv
A pointer to memory allocated with Marshal.AllocHGlobal(IntPtr).
cb
The new size of the allocated block. This is not a pointer; it is the byte count you are requesting, cast to type IntPtr. If you pass a pointer, it is treated as a size.

Returns

A pointer to the reallocated memory. This memory must be released using Marshal.FreeHGlobal(IntPtr).

Remarks

Marshal.ReAllocHGlobal(IntPtr, IntPtr) is one of two memory reallocation API methods in the System.Runtime.InteropServices.Marshal class. (Marshal.ReAllocCoTaskMem(IntPtr, int) is the other.)

This method exposes the Win32 tp://go.microsoft.com/fwlink/?LinkId=148780 function from Kernel32.dll. The returned pointer can differ from the original. If it is different, the contents of the original memory block have been copied to the new block, and the original memory block has been freed.

Requirements

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