using System.Buffers; using System.Runtime.CompilerServices; /*https://github.com/sidristij/memory-pools*/ namespace MemoryPools.Memory { public static class MemoryEx { [MethodImpl(MethodImplOptions.AggressiveInlining)] public static int Length(this IMemoryOwner that) => that.Memory.Length; [MethodImpl(MethodImplOptions.AggressiveInlining)] public static CountdownMemoryOwner AsCountdown(this CountdownMemoryOwner that, bool noDefaultOwner = false) => Pool>.Get().Init(that, 0, that.Memory.Length, noDefaultOwner); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static CountdownMemoryOwner AsCountdown(this CountdownMemoryOwner that, int offset, bool noDefaultOwner = false) => Pool>.Get().Init(that, offset, that.Memory.Length - offset, noDefaultOwner); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static CountdownMemoryOwner AsCountdown(this CountdownMemoryOwner that, int offset, int length, bool noDefaultOwner = false) => Pool>.Get().Init(that, offset, length, noDefaultOwner); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static IMemoryOwner Slice(this CountdownMemoryOwner that, int offset) => Slice(that, offset, that.Memory.Length - offset); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static IMemoryOwner Slice(this CountdownMemoryOwner that, int offset, int length) => that.AsCountdown(offset, length); } }