public PrimitiveColumnContainer(long length = 0)
 {
     while (length > 0)
     {
         if (Buffers.Count == 0)
         {
             Buffers.Add(new DataFrameBuffer <T>());
             NullBitMapBuffers.Add(new DataFrameBuffer <byte>());
         }
         DataFrameBuffer <T> lastBuffer = (DataFrameBuffer <T>)Buffers[Buffers.Count - 1];
         if (lastBuffer.Length == ReadOnlyDataFrameBuffer <T> .MaxCapacity)
         {
             lastBuffer = new DataFrameBuffer <T>();
             Buffers.Add(lastBuffer);
             NullBitMapBuffers.Add(new DataFrameBuffer <byte>());
         }
         int allocatable = (int)Math.Min(length, ReadOnlyDataFrameBuffer <T> .MaxCapacity);
         lastBuffer.EnsureCapacity(allocatable);
         DataFrameBuffer <byte> lastNullBitMapBuffer = (DataFrameBuffer <byte>)(NullBitMapBuffers[NullBitMapBuffers.Count - 1]);
         int nullBufferAllocatable = (allocatable + 7) / 8;
         lastNullBitMapBuffer.EnsureCapacity(nullBufferAllocatable);
         lastBuffer.Length           = allocatable;
         lastNullBitMapBuffer.Length = nullBufferAllocatable;
         length    -= allocatable;
         Length    += lastBuffer.Length;
         NullCount += lastBuffer.Length;
     }
 }
        public PrimitiveColumnContainer(ReadOnlyMemory <byte> buffer, ReadOnlyMemory <byte> nullBitMap, int length, int nullCount)
        {
            ReadOnlyDataFrameBuffer <T> dataBuffer;

            if (buffer.IsEmpty)
            {
                DataFrameBuffer <T> mutableBuffer = new DataFrameBuffer <T>();
                mutableBuffer.EnsureCapacity(length);
                mutableBuffer.Length = length;
                mutableBuffer.RawSpan.Fill(default(T));
                dataBuffer = mutableBuffer;
            }
            else
            {
                dataBuffer = new ReadOnlyDataFrameBuffer <T>(buffer, length);
            }
            Buffers.Add(dataBuffer);
            int bitMapBufferLength = (length + 7) / 8;
            ReadOnlyDataFrameBuffer <byte> nullDataFrameBuffer;

            if (nullBitMap.IsEmpty)
            {
                if (nullCount != 0)
                {
                    throw new ArgumentNullException(Strings.InconsistentNullBitMapAndNullCount, nameof(nullBitMap));
                }
                if (!buffer.IsEmpty)
                {
                    // Create a new bitMap with all the bits up to length set
                    var bitMap = new byte[bitMapBufferLength];
                    bitMap.AsSpan().Fill(255);
                    int lastByte = 1 << (length - (bitMapBufferLength - 1) * 8);
                    bitMap[bitMapBufferLength - 1] = (byte)(lastByte - 1);
                    nullDataFrameBuffer            = new DataFrameBuffer <byte>(bitMap, bitMapBufferLength);
                }
                else
                {
                    nullDataFrameBuffer = new DataFrameBuffer <byte>();
                }
            }
            else
            {
                if (nullBitMap.Length < bitMapBufferLength)
                {
                    throw new ArgumentException(Strings.InconsistentNullBitMapAndLength, nameof(nullBitMap));
                }
                nullDataFrameBuffer = new ReadOnlyDataFrameBuffer <byte>(nullBitMap, bitMapBufferLength);
            }
            NullBitMapBuffers.Add(nullDataFrameBuffer);
            Length    = length;
            NullCount = nullCount;
        }