Exemple #1
0
        public byte[] LeaseBytes(int minSize)
        {
            LocklessQueue <ImmutableTimestampedItem <byte[]> > container = this.FindContainer(minSize);

            if (container == null)
            {
                s_Log.WarnFormat("[ByteBufferPool] Not servicing request for {0} bytes", minSize);

                //we cant service a request for this size
                return(new byte[minSize]);
            }

            ImmutableTimestampedItem <byte[]> buffer;

            if (container.Dequeue(out buffer))
            {
                Interlocked.Add(ref _currAllocatedBytes, -buffer.Item.Length);
                return(buffer.Item);
            }
            else
            {
                int closestContainerSize = this.FindContainerSize(minSize);
                return(new byte[closestContainerSize]);
            }
        }
Exemple #2
0
        public void ReturnBytes(byte[] bytes)
        {
            LocklessQueue <ImmutableTimestampedItem <byte[]> > container = this.FindExactContainer(bytes.Length);

            if (container != null)
            {
                if (_currAllocatedBytes < _maxAllocatedBytes)
                {
                    Interlocked.Add(ref _currAllocatedBytes, bytes.Length);
                    container.Enqueue(new ImmutableTimestampedItem <byte[]>(bytes));
                }
            }
        }
        public void ReturnBytes(byte[] bytes)
        {
            LocklessQueue <byte[]> container = this.FindExactContainer(bytes.Length);

            if (container != null)
            {
                if (_currAllocatedBytes < _maxAllocatedBytes)
                {
                    Interlocked.Add(ref _currAllocatedBytes, bytes.Length);
                    container.Enqueue(bytes);
                }
            }
        }