DotNext by .NET Foundation and Contributors

<PackageReference Include="DotNext" Version="5.8.0" />

.NET API 503,240 bytes

 Memory

public static class Memory
Represents methods to work with memory pools and buffers.
public static MemoryOwner<T> AllocateAtLeast<T>(this MemoryAllocator<T> allocator, int length)

Allocates memory of at least length size.

public static MemoryOwner<T> AllocateAtLeast<T>(int length)

Rents a block of memory of at least length size from Shared pool.

public static MemoryOwner<T> AllocateExactly<T>(this MemoryAllocator<T> allocator, int length)

Allocates memory of length size.

public static MemoryOwner<T> AllocateExactly<T>(int length)

Rents a block of memory of the specified size from Shared pool.

public static ReadOnlySequence<T> Concat<T>(this ReadOnlyMemory<T> first, ReadOnlyMemory<T> second)

Converts two memory blocks to ReadOnlySequence<T> data type.

public static void CopyTo<T>(this ref ReadOnlySequence source, Span<T> destination, out int writtenCount)

Copies the contents from the source sequence into a destination span.

public static MemoryAllocator<T> GetArrayAllocator<T>()

Returns array allocator.

Returns an allocator of pinned arrays.

public static ref T GetReference<T>(ref MemoryOwner owner)

Gets managed pointer to the first element in the rented memory block.

public static void ReleaseAll<T>(this ref MemoryOwner owner) where T : IDisposable

Releases all resources encapsulated by the container.

public static void Resize<T>(this ref MemoryOwner owner, int newLength, MemoryAllocator<T> allocator = null)

Resizes the buffer.

public static MemoryAllocator<T> ToAllocator<T>(this ArrayPool<T> pool)

Converts array pool to the memory allocator.

public static MemoryAllocator<T> ToAllocator<T>(this MemoryPool<T> pool)

Converts memory pool to the memory allocator.

public static MemoryAllocator<T> ToAllocator<T>(this Func<int, IMemoryOwner<T>> provider)

Converts memory provider to the memory allocator.

public static ReadOnlySequence<T> ToReadOnlySequence<T>(this IEnumerable<ReadOnlyMemory<T>> chunks)

Converts the sequence of memory blocks to ReadOnlySequence<T> data type.

public static ReadOnlySequence<char> ToReadOnlySequence(this IEnumerable<string> strings)

Constructs a sequence of characters from a collection of strings.

public static ReadOnlyMemory<T> TrimLength<T>(this ReadOnlyMemory<T> memory, int maxLength)

Trims the memory block to specified length if it exceeds it. If length is less that maxLength then the original block returned.

public static Memory<T> TrimLength<T>(this Memory<T> memory, int maxLength)

Trims the memory block to specified length if it exceeds it. If length is less that maxLength then the original block returned.

public static bool TryGetBlock<T>(this ref ReadOnlySequence sequence, int count, out ReadOnlyMemory span)

Tries to get a contiguous block of memory from the specified sequence of elements.