Edit

Share via


ArrayPoolExtensions.EnsureCapacity<T> Method

Definition

Ensures that when the method returns array is not null and is at least capacity in length. Contents of array are not copied if a new array is rented.

public static void EnsureCapacity<T>(this System.Buffers.ArrayPool<T> pool, ref T[]? array, int capacity, bool clearArray = false);
static member EnsureCapacity : System.Buffers.ArrayPool<'T> * T[] * int * bool -> unit
<Extension()>
Public Sub EnsureCapacity(Of T) (pool As ArrayPool(Of T), ByRef array As T(), capacity As Integer, Optional clearArray As Boolean = false)

Type Parameters

T

The type of items into the target array given as input.

Parameters

pool
ArrayPool<T>

The target ArrayPool<T> instance used to rent and/or return the array.

array
T[]

The rented T array to ensure capacity for, or null to rent a new array.

capacity
Int32

The minimum length of array when the method returns.

clearArray
Boolean

Indicates whether the contents of the array should be cleared if returned to the pool.

Exceptions

Thrown when capacity is less than 0.

Remarks

When this method returns, the caller must not use any references to the old array anymore.

Applies to