Marshal.ReAllocHGlobal(IntPtr, IntPtr) Method

Definition

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

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

Parameters

pv
IntPtr

nativeint

A pointer to memory allocated with AllocHGlobal(IntPtr).

cb
IntPtr

nativeint

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

IntPtr

nativeint

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

Attributes

Exceptions

There is insufficient memory to satisfy the request.

Remarks

ReAllocHGlobal is one of two memory reallocation API methods in the Marshal class. (Marshal.ReAllocCoTaskMem is the other.)

This method exposes the Win32 GlobalReAlloc 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.

Applies to

See also