Sharpen.PipedInputStream.TryAllocate C# (CSharp) Method

TryAllocate() private method

private TryAllocate ( int len ) : int
len int
return int
        int TryAllocate(int len)
        {
            int free;
            if (start <= end) {
                free = (buffer.Length - end) + start;
            } else {
                free = start - end;
            }
            if (free <= len) {
                if (!allowGrow)
                    return free > 0 ? free - 1 : 0;
                int sizeInc = (len - free) + 1;
                byte[] destinationArray = new byte[buffer.Length + sizeInc];
                if (start <= end) {
                    Array.Copy (buffer, start, destinationArray, start, end - start);
                } else {
                    Array.Copy (buffer, 0, destinationArray, 0, end);
                    Array.Copy (buffer, start, destinationArray, start + sizeInc, buffer.Length - start);
                    start += sizeInc;
                }
                buffer = destinationArray;
            }
            return len;
        }