< Summary

Class:Azure.Storage.StorageMemoryPool
Assembly:Azure.Storage.Files.Shares
File(s):C:\Git\azure-sdk-for-net\sdk\storage\Azure.Storage.Common\src\Shared\StorageMemoryPool.cs
Covered lines:0
Uncovered lines:20
Coverable lines:20
Total lines:66
Line coverage:0% (0 of 20)
Covered branches:0
Total branches:2
Branch coverage:0% (0 of 2)

Metrics

MethodCyclomatic complexity Line coverage Branch coverage
.ctor(...)-0%100%
get_MaxBufferSize()-0%100%
Rent(...)-0%100%
Dispose(...)-0%100%
.ctor(...)-0%100%
get_Memory()-0%100%
Dispose()-0%0%

File(s)

C:\Git\azure-sdk-for-net\sdk\storage\Azure.Storage.Common\src\Shared\StorageMemoryPool.cs

#LineLine coverage
 1// Copyright (c) Microsoft Corporation. All rights reserved.
 2// Licensed under the MIT License.
 3
 4using System;
 5using System.Buffers;
 6using System.IO;
 7using System.Threading;
 8using System.Threading.Tasks;
 9
 10namespace Azure.Storage
 11{
 12    /// <summary>
 13    /// Private memory pool specific to Azure storage transfers, based on ArrayPool.
 14    /// </summary>
 15    internal class StorageMemoryPool : MemoryPool<byte>
 16    {
 17        private ArrayPool<byte> _arrayPool;
 18
 019        public StorageMemoryPool(int maxArrayLength, int maxArraysPerBucket)
 20        {
 021            MaxBufferSize = maxArrayLength;
 022            _arrayPool = ArrayPool<byte>.Create(maxArrayLength, maxArraysPerBucket);
 023        }
 24
 025        public override int MaxBufferSize { get; }
 26
 27        public override IMemoryOwner<byte> Rent(int minBufferSize = -1)
 28        {
 029            lock (_arrayPool)
 30            {
 031                return new StorageMemoryOwner(this, minBufferSize);
 32            }
 033        }
 34
 035        protected override void Dispose(bool disposing) => _arrayPool = default;
 36
 37        private class StorageMemoryOwner : IMemoryOwner<byte>
 38        {
 039            public StorageMemoryOwner(StorageMemoryPool pool, int minimumLength)
 40            {
 041                _arrayPool = pool._arrayPool;
 042                Memory = _arrayPool.Rent(minimumLength);
 043            }
 44
 45            private ArrayPool<byte> _arrayPool;
 46
 047            public Memory<byte> Memory { get; private set; }
 48
 49            #region IDisposable Support
 50            private bool _disposedValue = false; // To detect redundant calls
 51
 52            public void Dispose()
 53            {
 054                if (!_disposedValue)
 55                {
 056                    _disposedValue = true;
 57
 058                    _arrayPool.Return(Memory.ToArray());
 059                    _arrayPool = null;
 060                    Memory = null;
 61                }
 062            }
 63            #endregion
 64        }
 65    }
 66}