Пример #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]);
            }
        }
Пример #2
0
        public T LeaseObject()
        {
            T obj;

            if (_storage.Dequeue(out obj))
            {
                Interlocked.Decrement(ref _currAllocatedObjects);
                return(obj);
            }
            else
            {
                if (_ctorFunc != null)
                {
                    return(_ctorFunc());
                }
                else
                {
                    return(new T());
                }
            }
        }