Marshal.ReAllocHGlobal(IntPtr, IntPtr) Method
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
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
- 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.
nativeint
A pointer to the reallocated memory. This memory must be released using FreeHGlobal(IntPtr).
- Attributes
There is insufficient memory to satisfy the request.
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.
Product | Versions |
---|---|
.NET | Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9 |
.NET Framework | 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1 |
.NET Standard | 1.1, 1.2, 1.3, 1.4, 1.5, 1.6, 2.0, 2.1 |
UWP | 10.0 |
.NET feedback
.NET is an open source project. Select a link to provide feedback: