Example #1
0
 public override void ReturnBuffer(byte[] buffer)
 {
     InternalBufferManager.PooledBufferManager.BufferPool bufferPool = this.FindPool((int)buffer.Length);
     if (bufferPool != null)
     {
         if ((int)buffer.Length == bufferPool.BufferSize)
         {
             if (bufferPool.Return(buffer))
             {
                 bufferPool.IncrementCount();
             }
         }
         else
         {
             throw Fx.Exception.Argument("buffer", InternalSR.BufferIsNotRightSizeForBufferManager);
         }
     }
 }
Example #2
0
            private void ChangeQuota(ref InternalBufferManager.PooledBufferManager.BufferPool bufferPool, int delta)
            {
                if (TraceCore.BufferPoolChangeQuotaIsEnabled(Fx.Trace))
                {
                    TraceCore.BufferPoolChangeQuota(Fx.Trace, bufferPool.BufferSize, delta);
                }
                InternalBufferManager.PooledBufferManager.BufferPool bufferPool1 = bufferPool;
                int limit = bufferPool1.Limit + delta;

                InternalBufferManager.PooledBufferManager.BufferPool bufferPool2 = InternalBufferManager.PooledBufferManager.BufferPool.CreatePool(bufferPool1.BufferSize, limit);
                for (int i = 0; i < limit; i++)
                {
                    byte[] numArray = bufferPool1.Take();
                    if (numArray == null)
                    {
                        break;
                    }
                    bufferPool2.Return(numArray);
                    bufferPool2.IncrementCount();
                }
                InternalBufferManager.PooledBufferManager bufferSize = this;
                bufferSize.remainingMemory = bufferSize.remainingMemory - (long)(bufferPool1.BufferSize * delta);
                bufferPool = bufferPool2;
            }