예제 #1
0
 public override byte[] TakeBuffer(int bufferSize)
 {
     InternalBufferManager.PooledBufferManager.BufferPool bufferPool = this.FindPool(bufferSize);
     if (bufferPool == null)
     {
         if (TraceCore.BufferPoolAllocationIsEnabled(Fx.Trace))
         {
             TraceCore.BufferPoolAllocation(Fx.Trace, bufferSize);
         }
         return(Fx.AllocateByteArray(bufferSize));
     }
     byte[] array = bufferPool.Take();
     if (array != null)
     {
         bufferPool.DecrementCount();
         return(array);
     }
     if (bufferPool.Peak == bufferPool.Limit)
     {
         bufferPool.Misses++;
         if (++this.totalMisses >= 8)
         {
             this.TuneQuotas();
         }
     }
     if (TraceCore.BufferPoolAllocationIsEnabled(Fx.Trace))
     {
         TraceCore.BufferPoolAllocation(Fx.Trace, bufferPool.BufferSize);
     }
     return(Fx.AllocateByteArray(bufferPool.BufferSize));
 }