예제 #1
0
        public void Dispose()
        {
            for (; ;)
            {
                int index = full.Pop();

                if (index < 0)
                {
                    break;
                }

                array[index].Value.Dispose();
                array[index].Value = default(T);
            }
        }
예제 #2
0
        public bool Recycle(Socket socket, AddressFamily family)
        {
            if (isEnabled)
            {
                int index = empty.Pop();

                if (index >= 0)
                {
                    array[index].Value = socket;
                    GetFull(family).Push(index);

                    return(true);
                }
            }

            return(false);
        }
예제 #3
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);
                }
            }
        }
예제 #4
0
        public void Free(ArraySegment <byte> segment)
        {
            int bufferIndex = 0;

            while (bufferIndex < buffers.Length && buffers[bufferIndex] != segment.Array)
            {
                bufferIndex++;
            }

            if (bufferIndex >= buffers.Length)
            {
                throw new ArgumentException("SmartBufferPool.Free, segment.Array is invalid");
            }

            int index = empty.Pop();

            array[index].Value = ((long)bufferIndex << 32) + segment.Offset;

            ready[GetBitOffset(segment.Count)].Push(index);
        }
예제 #5
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
            }
        }