コード例 #1
0
        internal Releaser Rent(int minCapacity, out ByteBuffer buffer)
        {
            if (minCapacity <= SmallMessageBufferSize)
            {
                return(Rent(SmallMessageBuffers, SmallMessageBufferSize, out buffer));
            }

            if (minCapacity <= MediumMessageBufferSize)
            {
                return(Rent(MediumMessageBuffers, MediumMessageBufferSize, out buffer));
            }

            if (minCapacity <= LargeMessageBufferSize)
            {
                return(Rent(LargeMessageBuffers, LargeMessageBufferSize, out buffer));
            }

            lock (MassiveBuffers) {
                for (int i = 0; i < MassiveBuffers.Count; i++)
                {
                    if ((buffer = MassiveBuffers.Dequeue()).Data.Length >= minCapacity)
                    {
                        return(new Releaser(MassiveBuffers, buffer));
                    }
                    else
                    {
                        MassiveBuffers.Enqueue(buffer);
                    }
                }

                buffer = new ByteBuffer(minCapacity);
                return(new Releaser(MassiveBuffers, buffer));
            }
        }
コード例 #2
0
        Releaser Rent(int capacity, out ByteBuffer buffer)
        {
            if (capacity <= SmallMessageBufferSize)
            {
                return(Rent(SmallMessageBuffers, SmallMessageBufferSize, out buffer));
            }

            if (capacity <= LargeMessageBufferSize)
            {
                return(Rent(LargeMessageBuffers, LargeMessageBufferSize, out buffer));
            }

            lock (MassiveBuffers) {
                for (int i = 0; i < MassiveBuffers.Count; i++)
                {
                    if ((buffer = MassiveBuffers.Dequeue()).Span.Length >= capacity)
                    {
                        return(new Releaser(MassiveBuffers, buffer));
                    }
                    else
                    {
                        MassiveBuffers.Enqueue(buffer);
                    }
                }

                buffer = new ByteBuffer(new Memory <byte> (new byte[capacity]), CreateSocketAsyncArgs);
                return(new Releaser(MassiveBuffers, buffer));
            }
        }
コード例 #3
0
        public byte[] Rent(int minCapacity)
        {
            if (minCapacity <= SmallMessageBufferSize)
            {
                return(Rent(SmallMessageBuffers, SmallMessageBufferSize));
            }

            if (minCapacity <= MediumMessageBufferSize)
            {
                return(Rent(MediumMessageBuffers, MediumMessageBufferSize));
            }

            if (minCapacity <= LargeMessageBufferSize)
            {
                return(Rent(LargeMessageBuffers, LargeMessageBufferSize));
            }

            lock (MassiveBuffers)
            {
                byte[] buffer;
                for (int i = 0; i < MassiveBuffers.Count; i++)
                {
                    if ((buffer = MassiveBuffers.Dequeue()).Length >= minCapacity)
                    {
                        return(buffer);
                    }
                    else
                    {
                        MassiveBuffers.Enqueue(buffer);
                    }
                }

                buffer = new byte[minCapacity];
                lock (AllocatedBuffers)
                    AllocatedBuffers.Add(buffer);
                return(buffer);
            }
        }