Marshal.ReAllocHGlobal(IntPtr, IntPtr) Marshal.ReAllocHGlobal(IntPtr, IntPtr) Marshal.ReAllocHGlobal(IntPtr, IntPtr) 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);
static member ReAllocHGlobal : nativeint * nativeint -> nativeint
Public Shared Function ReAllocHGlobal (pv As IntPtr, cb As IntPtr) As IntPtr

Parameters

pv
IntPtr IntPtr IntPtr IntPtr

A pointer to memory allocated with AllocHGlobal(IntPtr).

cb
IntPtr IntPtr IntPtr IntPtr

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 FreeHGlobal(IntPtr).

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.

Security

SecurityCriticalAttribute
requires full trust for the immediate caller. This member cannot be used by partially trusted or transparent code.

Applies to

See also