< Summary

Line coverage
0%
Covered lines: 0
Uncovered lines: 8
Coverable lines: 8
Total lines: 74
Line coverage: 0%
Branch coverage
N/A
Covered branches: 0
Total branches: 0
Branch coverage: N/A
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Cyclomatic complexity NPath complexity Sequence coverage
CreateMemory(...)100%110%
CreateMemory(...)100%110%
TryGetArray(...)100%110%
System.IDisposable.Dispose()100%110%

File(s)

https://raw.githubusercontent.com/dotnet/runtime/811a7eabb75c42db53440e8ba3f60c07511cfd1f/src/libraries/System.Private.CoreLib/src/System/Buffers/MemoryManager.cs

#LineLine coverage
 1// Licensed to the .NET Foundation under one or more agreements.
 2// The .NET Foundation licenses this file to you under the MIT license.
 3
 4using System.Runtime.CompilerServices;
 5
 6namespace System.Buffers
 7{
 8    /// <summary>
 9    /// Manager of <see cref="Memory{T}"/> that provides the implementation.
 10    /// </summary>
 11    public abstract class MemoryManager<T> : IMemoryOwner<T>, IPinnable
 12    {
 13        /// <summary>
 14        /// Returns a <see cref="Memory{T}"/>.
 15        /// </summary>
 016        public virtual Memory<T> Memory => new Memory<T>(this, GetSpan().Length);
 17
 18        /// <summary>
 19        /// Returns a span wrapping the underlying memory.
 20        /// </summary>
 21        public abstract Span<T> GetSpan();
 22
 23        /// <summary>
 24        /// Returns a handle to the memory that has been pinned and hence its address can be taken.
 25        /// </summary>
 26        /// <param name="elementIndex">The offset to the element within the memory at which the returned <see cref="Memo
 27        public abstract MemoryHandle Pin(int elementIndex = 0);
 28
 29        /// <summary>
 30        /// Lets the garbage collector know that the object is free to be moved now.
 31        /// </summary>
 32        public abstract void Unpin();
 33
 34        /// <summary>
 35        /// Returns a <see cref="Memory{T}"/> for the current <see cref="MemoryManager{T}"/>.
 36        /// </summary>
 37        /// <param name="length">The element count in the memory, starting at offset 0.</param>
 38        [MethodImpl(MethodImplOptions.AggressiveInlining)]
 039        protected Memory<T> CreateMemory(int length) => new Memory<T>(this, length);
 40
 41        /// <summary>
 42        /// Returns a <see cref="Memory{T}"/> for the current <see cref="MemoryManager{T}"/>.
 43        /// </summary>
 44        /// <param name="start">The offset to the element which the returned memory starts at.</param>
 45        /// <param name="length">The element count in the memory, starting at element offset <paramref name="start"/>.</
 46        [MethodImpl(MethodImplOptions.AggressiveInlining)]
 047        protected Memory<T> CreateMemory(int start, int length) => new Memory<T>(this, start, length);
 48
 49        /// <summary>
 50        /// Returns an array segment.
 51        /// <remarks>Returns the default array segment if not overridden.</remarks>
 52        /// </summary>
 53        protected internal virtual bool TryGetArray(out ArraySegment<T> segment)
 54        {
 055            segment = default;
 056            return false;
 57        }
 58
 59        /// <summary>
 60        /// Implements IDisposable.
 61        /// </summary>
 62        void IDisposable.Dispose()
 63        {
 064            Dispose(disposing: true);
 065            GC.SuppressFinalize(this);
 066        }
 67
 68        /// <summary>
 69        /// Clean up of any leftover managed and unmanaged resources.
 70        /// </summary>
 71        protected abstract void Dispose(bool disposing);
 72    }
 73}
 74