Table of Contents

Method Realloc

Namespace
Alternet.UI
Assembly
Alternet.UI.Common.dll

Realloc(IntPtr, int)

Reallocates the given area of memory (implicitly creating objects in the destination area). It must be previously allocated by Alloc(int) and not yet freed with FreeMem(IntPtr), otherwise, the results are undefined.

IntPtr Realloc(IntPtr ptr, int newSize)

Parameters

ptr nint

Pointer to the object to realloc.

newSize int

Number of bytes to allocate.

Returns

nint

On success, returns a pointer to the beginning of newly allocated memory. To avoid a memory leak, the returned pointer must be deallocated with FreeMem(IntPtr) or Realloc(IntPtr, int). The original pointer ptr is invalidated and any access to it is undefined behavior (even if reallocation was in-place). On failure, returns a null pointer. The original pointer ptr remains valid and may need to be deallocated with FreeMem(IntPtr).

Remarks

The reallocation is done by either: Method 1. Expanding or contracting the existing area pointed to by ptr, if possible. The contents of the area remain unchanged up to the lesser of the new and old sizes. If the area is expanded, the contents of the new part of the array are undefined. Method 2. Allocating a new memory block of size newSize bytes, copying memory area with size equal the lesser of the new and the old sizes, and freeing the old block. If there is not enough memory, the old memory block is not freed and null pointer is returned.