Squared.Data.Mangler.Internal.StreamRef.EnsureCapacity C# (CSharp) Method

EnsureCapacity() protected method

protected EnsureCapacity ( long capacity ) : void
capacity long
return void
        protected void EnsureCapacity(long capacity)
        {
            if (capacity <= StreamCapacity)
                return;

            // We grow the stream by a fixed amount every time we run out
            //  of space. Doubling or some other algorithm might be better,
            //  but this is simple and predictable.
            long newCapacity = StreamCapacity;
            if (StreamCapacity >= DoublingThreshold) {
                while (newCapacity < capacity)
                    newCapacity += PostDoublingGrowthRate;
            } else {
                while (newCapacity < capacity)
                    newCapacity *= 2;
            }

            if (LengthChanging != null)
                LengthChanging(this, EventArgs.Empty);

            DisposeViews();

            CreateHandles(newCapacity);

            if (LengthChanged != null)
                LengthChanged(this, EventArgs.Empty);
        }