Table of Contents

Class MemorySequencePool<T>

Namespace
LfrlAnvil.Memory
Assembly
LfrlAnvil.Core.dll

Represents a pool of RentedMemorySequence<T> instances.

public class MemorySequencePool<T>

Type Parameters

T

Element type.

Inheritance
MemorySequencePool<T>
Inherited Members
Extension Methods

Constructors

MemorySequencePool(int)

Creates a new MemorySequencePool<T> instance.

public MemorySequencePool(int minSegmentLength)

Parameters

minSegmentLength int

Minimum single pool segment length. The actual value will be rounded up to a power of two.

Exceptions

ArgumentOutOfRangeException

When minSegmentLength is less than 1 or greater than 2^30.

Properties

ClearReturnedSequences

Specifies whether or not this pool clears the contents of memory sequences that get returned to the pool.

public bool ClearReturnedSequences { get; set; }

Property Value

bool

Report

Creates a new MemorySequencePool<T>.ReportInfo instance.

public MemorySequencePool<T>.ReportInfo Report { get; }

Property Value

MemorySequencePool<T>.ReportInfo

SegmentLength

Length of a single pool segment.

public int SegmentLength { get; }

Property Value

int

Methods

GreedyRent(int)

Creates a new RentedMemorySequence<T> instance from this pool.

public RentedMemorySequence<T> GreedyRent(int length = 0)

Parameters

length int

Initial size of the rented sequence. Equal to 0 by default.

Returns

RentedMemorySequence<T>

New RentedMemorySequence<T> instance.

Remarks

This method always uses or allocates segments at the tail of the pool.

Rent(int)

Creates a new RentedMemorySequence<T> instance from this pool.

public RentedMemorySequence<T> Rent(int length)

Parameters

length int

Size of the rented sequence.

Returns

RentedMemorySequence<T>

New RentedMemorySequence<T> instance, or Empty when length is less than 1.

Remarks

This method attempts to reuse fragmented segments.

TrimExcess()

Attempts to deallocate unused segments at the tail of this pool.

public void TrimExcess()