แก้ไข

แชร์ผ่าน


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

Important

This native memory allocator is a legacy API that should be used exclusively when called for by specific Win32 APIs on the Windows platform. When targeting .NET 6 or later, use the NativeMemory class on all platforms to allocate native memory. When targeting .NET 6 or earlier, use AllocCoTaskMem on all platforms to allocate native memory.

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