Beispiel #1
0
            public PooledBufferManager(long maxMemoryToPool, int maxBufferSize)
            {
                int num;

                this.tuningLock      = new object();
                this.memoryLimit     = maxMemoryToPool;
                this.remainingMemory = maxMemoryToPool;
                List <InternalBufferManager.PooledBufferManager.BufferPool> bufferPools = new List <InternalBufferManager.PooledBufferManager.BufferPool>();
                int num1 = 128;

                while (true)
                {
                    long num2 = this.remainingMemory / (long)num1;
                    if (num2 > (long)0x7fffffff)
                    {
                        num = 0x7fffffff;
                    }
                    else
                    {
                        num = (int)num2;
                    }
                    int num3 = num;
                    if (num3 > 1)
                    {
                        num3 = 1;
                    }
                    bufferPools.Add(InternalBufferManager.PooledBufferManager.BufferPool.CreatePool(num1, num3));
                    InternalBufferManager.PooledBufferManager pooledBufferManager = this;
                    pooledBufferManager.remainingMemory = pooledBufferManager.remainingMemory - (long)num3 * (long)num1;
                    if (num1 >= maxBufferSize)
                    {
                        break;
                    }
                    long num4 = (long)num1 * (long)2;
                    if (num4 <= (long)maxBufferSize)
                    {
                        num1 = (int)num4;
                    }
                    else
                    {
                        num1 = maxBufferSize;
                    }
                }
                this.bufferPools = bufferPools.ToArray();
                this.bufferSizes = new int[(int)this.bufferPools.Length];
                int num5 = 0;

                while (num5 < (int)this.bufferPools.Length)
                {
                    this.bufferSizes[num5] = this.bufferPools[num5].BufferSize;
                    num5++;
                }
            }
Beispiel #2
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));
     }
     else
     {
         byte[] numArray = bufferPool.Take();
         if (numArray == null)
         {
             if (bufferPool.Peak == bufferPool.Limit)
             {
                 InternalBufferManager.PooledBufferManager.BufferPool misses = bufferPool;
                 misses.Misses = misses.Misses + 1;
                 InternalBufferManager.PooledBufferManager pooledBufferManager = this;
                 int num  = pooledBufferManager.totalMisses + 1;
                 int num1 = num;
                 pooledBufferManager.totalMisses = num;
                 if (num1 >= 8)
                 {
                     this.TuneQuotas();
                 }
             }
             if (TraceCore.BufferPoolAllocationIsEnabled(Fx.Trace))
             {
                 TraceCore.BufferPoolAllocation(Fx.Trace, bufferPool.BufferSize);
             }
             return(Fx.AllocateByteArray(bufferPool.BufferSize));
         }
         else
         {
             bufferPool.DecrementCount();
             return(numArray);
         }
     }
 }
Beispiel #3
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;
            }