using MemoryPools.Memory.Pooling; using System; using System.Runtime.CompilerServices; /*https://github.com/sidristij/memory-pools*/ namespace MemoryPools.Memory { internal sealed class InternalArraysPool { private const int MinBufferSize = 128; [MethodImpl(MethodImplOptions.AggressiveInlining)] public static CountdownMemoryOwner Rent(int length) { return Rent(length); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static CountdownMemoryOwner Rent(int length, bool noDefaultOwner = false) { var realLength = length; var allocLength = length > MinBufferSize ? length : MinBufferSize; var owner = BucketsBasedCrossThreadsMemoryPool.Shared.Rent(allocLength); return owner.AsCountdown(0, realLength, noDefaultOwner); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static CountdownMemoryOwner RentFrom(ReadOnlySpan source, bool noDefaultOwner = false) { var mem = Rent(source.Length, noDefaultOwner); source.CopyTo(mem.Memory.Span); return mem; } } }