예제 #1
0
            void Increase(int count = DEFAULT_POOL_INCREASE_SIZE)
            {
                for (int i = 0; i < count; i++)
                {
                    Infrastructure.FixedSizeBuffer b = Infrastructure.FixedSizeBuffer.New(_bufferSize, this);
                    this.Return(b);
                }

                ////Console.WriteLine($"BufferPool Increase {count}; CurrentPoolSize= {CurrentPoolSize()}.");
            }
예제 #2
0
            public void Return(Infrastructure.FixedSizeBuffer buffer)//in
            {
                Throw.IfNull(() => buffer);

                //To avoid returning twice.
                if (0 == Interlocked.CompareExchange(ref buffer._inThePool, 1, 0))
                {
                    //Throw.IfNotEqualsTo(() => buffer.Bytes.Length, this._bufferSize);
                    if (buffer.Memory.Length != this._bufferSize)
                    {
                        Interlocked.Exchange(ref buffer._inThePool, 0);
                        throw new InvalidOperationException("invalid buffer.");
                    }

                    buffer.EraseData();
                    buffer.Memory = null;

                    _pool.Push(buffer);
                }
            }