Ejemplo n.º 1
0
            public override byte[] TakeBuffer(int bufferSize)
            {
                Fx.Assert(bufferSize >= 0, "caller must ensure a non-negative argument");

                BufferPool bufferPool = FindPool(bufferSize);

                byte[] returnValue;
                if (bufferPool != null)
                {
                    byte[] buffer = bufferPool.Take();
                    if (buffer != null)
                    {
                        bufferPool.DecrementCount();
                        returnValue = buffer;
                    }
                    else
                    {
                        if (bufferPool.Peak == bufferPool.Limit)
                        {
                            bufferPool.Misses++;
                            if (++_totalMisses >= maxMissesBeforeTuning)
                            {
                                TuneQuotas();
                            }
                        }

                        if (TraceCore.BufferPoolAllocationIsEnabled(Fx.Trace))
                        {
                            TraceCore.BufferPoolAllocation(Fx.Trace, bufferPool.BufferSize);
                        }

                        returnValue = Fx.AllocateByteArray(bufferPool.BufferSize);
                    }
                }
                else
                {
                    if (TraceCore.BufferPoolAllocationIsEnabled(Fx.Trace))
                    {
                        TraceCore.BufferPoolAllocation(Fx.Trace, bufferSize);
                    }

                    returnValue = Fx.AllocateByteArray(bufferSize);
                }

#if DEBUG && !FEATURE_NETNATIVE
                string dummy;
                _buffersPooled.TryRemove(returnValue.GetHashCode(), out dummy);
#endif //DEBUG

                return(returnValue);
            }
Ejemplo n.º 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);
         }
     }
 }
Ejemplo n.º 3
0
            public override byte[] TakeBuffer(int bufferSize)
            {
                BufferPool pool = this.FindPool(bufferSize);

                if (pool == null)
                {
                    return(Fx.AllocateByteArray(bufferSize));
                }
                byte[] buffer = pool.Take();
                if (buffer != null)
                {
                    pool.DecrementCount();
                    return(buffer);
                }
                if (pool.Peak == pool.Limit)
                {
                    pool.Misses++;
                    if (++this.totalMisses >= 8)
                    {
                        this.TuneQuotas();
                    }
                }
                return(Fx.AllocateByteArray(pool.BufferSize));
            }
Ejemplo n.º 4
0
 public override byte[] TakeBuffer(int bufferSize)
 {
     return(Fx.AllocateByteArray(bufferSize));
 }