예제 #1
0
        public void Dispose()
        {
            if (isEnabled)
            {
                isEnabled = false;

                int index;
                while ((index = full4.Pop()) >= 0)
                {
                    array[index].Value.Close();
                    empty.Push(index);
                }

                while ((index = full6.Pop()) >= 0)
                {
                    array[index].Value.Close();
                    empty.Push(index);
                }
            }
        }
예제 #2
0
        public void Put(T value)
        {
            value.IsPooled = true;

            int index = value.Index;

            if (index >= 0)
            {
                value.SetDefaultValue();

                array[index].Value = value;

                full.Push(index);
            }
            else
            {
                value.Dispose();
            }
        }
예제 #3
0
        private bool GetAllocated(int size, out int index, out int offset)
        {
            int itemIndex = ready[GetBitOffset(size)].Pop();

            if (itemIndex >= 0)
            {
                index  = (int)(array[itemIndex].Value >> 32);
                offset = (int)array[itemIndex].Value;

                empty.Push(itemIndex);

                return(true);
            }
            else
            {
                index  = -1;
                offset = -1;

                return(false);
            }
        }
예제 #4
0
        public void Put(T value)
        {
            value.IsPooled = true;

            int index = empty.Pop();

            if (index >= 0)
            {
                value.SetDefaultValue();

                array[index].Value = value;

                full.Push(index);
            }
            else
            {
                value.Dispose();
#if DEBUG
                throw new Exception(@"BufferPool too small");
#endif
            }
        }
예제 #5
0
        public T Get()
        {
            T result = default(T);

            int index = full.Pop();

            if (index >= 0)
            {
                result             = array[index].Value;
                array[index].Value = default(T);

                empty.Push(index);
            }
            else
            {
                result = new T();
                result.SetDefaultValue();

                Interlocked.Increment(ref created);
            }

            result.IsPooled = false;
            return(result);
        }