ServiceStack.Text.RecyclableMemoryStreamManager.ReturnBlocks C# (CSharp) Méthode

ReturnBlocks() private méthode

Returns the blocks to the pool
blocks is null blocks contains buffers that are the wrong size (or null) for this memory manager
private ReturnBlocks ( ICollection blocks, string tag ) : void
blocks ICollection Collection of blocks to return to the pool
tag string The tag of the stream returning these blocks, for logging if necessary.
Résultat void
        internal void ReturnBlocks(ICollection<byte[]> blocks, string tag)
        {
            if (blocks == null)
            {
                throw new ArgumentNullException("blocks");
            }

            var bytesToReturn = blocks.Count * this.BlockSize;
            Interlocked.Add(ref this.smallPoolInUseSize, -bytesToReturn);

            foreach (var block in blocks)
            {
                if (block == null || block.Length != this.BlockSize)
                {
                    throw new ArgumentException("blocks contains buffers that are not BlockSize in length");
                }
            }

            foreach (var block in blocks)
            {
                if (this.MaximumFreeSmallPoolBytes == 0 || this.SmallPoolFreeSize < this.MaximumFreeSmallPoolBytes)
                {
                    Interlocked.Add(ref this.smallPoolFreeSize, this.BlockSize);
                    this.smallPool.Push(block);
                }
                else
                {
                    Events.Write.MemoryStreamDiscardBuffer(Events.MemoryStreamBufferType.Small, tag,
                                                           Events.MemoryStreamDiscardReason.EnoughFree);
                    if (this.BlockDiscarded != null)
                    {
                        this.BlockDiscarded();
                    }
                    break;
                }
            }

            if (this.UsageReport != null)
            {
                this.UsageReport(this.smallPoolInUseSize, this.smallPoolFreeSize, this.LargePoolInUseSize,
                                 this.LargePoolFreeSize);
            }
        }