SocketServers.StreamBuffer.Resize C# (CSharp) Method

Resize() public method

public Resize ( int capacity ) : bool
capacity int
return bool
        public bool Resize(int capacity)
        {
            if (capacity > BufferManager.MaxSize)
                return false;

            if (capacity < Count)
                return false;

            if (Capacity != capacity)
            {
                Capacity = capacity;

                if (capacity > segment.Count)
                {
                    var old = segment;
                    segment = BufferManager.Allocate(capacity);

                    if (old.IsValid())
                    {
                        if (Count > 0)
                            Buffer.BlockCopy(old.Array, old.Offset, segment.Array, segment.Offset, Count);
                        BufferManager.Free(ref old);
                    }
                }
            }

            return true;
        }