Esempio n. 1
0
        private void EnsureCapacity(int additionalCapacity)
        {
            var requiredCapacity = position + additionalCapacity;

            if (requiredCapacity < 0)
            {
                var s = string.Format("Insufficient capacity: position=%d additional=%d", position, additionalCapacity);
                throw new InvalidOperationException(s);
            }
            if (requiredCapacity > capacity)
            {
                var newCapacity = QuickMath.NextPowerOfTwo(requiredCapacity);
                var newBuffer   = new byte[newCapacity];
                Array.Copy(protocolBuffer.ByteArray(), 0, newBuffer, 0, capacity);
                capacity = newCapacity;
                protocolBuffer.Wrap(newBuffer);
            }
        }
        private void EnsureCapacity(int additionalCapacity)
        {
            var requiredCapacity = _position + additionalCapacity;

            if (requiredCapacity < 0)
            {
                var s = string.Format("Insufficient capacity: position={0} additional={1}", _position,
                                      additionalCapacity);
                throw new InvalidOperationException(s);
            }
            if (requiredCapacity > _capacity)
            {
                var newCapacity = QuickMath.NextPowerOfTwo(requiredCapacity);
                var newBuffer   = new byte[newCapacity];
                Buffer.BlockCopy(_protocolBuffer.ByteArray(), 0, newBuffer, 0, _capacity);
                _capacity = newCapacity;
                _protocolBuffer.Wrap(newBuffer);
            }
        }