Esempio n. 1
0
 /// <summary>
 /// Initializes a new writer with the default initial capacity.
 /// </summary>
 /// <param name="allocator">The allocator of internal buffer.</param>
 public PooledBufferWriter(MemoryAllocator <T>?allocator = null)
 {
     this.allocator = allocator;
 }
Esempio n. 2
0
 internal void Realloc(MemoryAllocator <T>?allocator, int length)
 {
     owner.Dispose();
     owner = allocator.Invoke(length, false);
 }
Esempio n. 3
0
 internal PooledMemoryChunk(MemoryAllocator <T>?allocator, int length, MemoryChunk?previous = null)
     : base(previous)
 {
     owner = allocator.Invoke(length, false);
 }
Esempio n. 4
0
 /// <summary>
 /// Initializes a new writer with the default initial capacity.
 /// </summary>
 /// <param name="allocator">The allocator of internal buffer.</param>
 public PooledBufferWriter(MemoryAllocator <T>?allocator)
 {
     this.allocator = allocator ?? ArrayPool <T> .Shared.ToAllocator();
 }
Esempio n. 5
0
 internal BufferedStreamWriter(Stream output, MemoryAllocator <byte> allocator)
 {
     this.output    = output;
     this.allocator = allocator;
 }
Esempio n. 6
0
 public static void ArrayAllocation()
 {
     using var owner = MemoryAllocator.CreateArrayAllocator <int>().Invoke(4, false);
     Equal(4, owner.Length);
 }
Esempio n. 7
0
        /// <summary>
        /// Initializes a new builder with the specified size of memory block.
        /// </summary>
        /// <param name="chunkSize">The size of the memory block representing single segment within sequence.</param>
        /// <param name="growth">Specifies how the memory should be allocated for each subsequent chunk in this buffer.</param>
        /// <param name="allocator">The allocator used to rent the segments.</param>
        /// <exception cref="ArgumentOutOfRangeException"><paramref name="chunkSize"/> is less than or equal to zero.</exception>
        public SparseBufferWriter(int chunkSize, SparseBufferGrowth growth = SparseBufferGrowth.None, MemoryAllocator <T>?allocator = null)
        {
            if (chunkSize <= 0)
            {
                throw new ArgumentOutOfRangeException(nameof(chunkSize));
            }

            this.chunkSize = chunkSize;
            this.allocator = allocator;

            unsafe
            {
                this.growth = growth switch
                {
                    SparseBufferGrowth.Linear => & BufferHelpers.LinearGrowth,
                    SparseBufferGrowth.Exponential => & BufferHelpers.ExponentialGrowth,
                    _ => & BufferHelpers.NoGrowth,
                };
            }
        }
Esempio n. 8
0
 /// <summary>
 /// Initializes a new builder with the specified size of memory block.
 /// </summary>
 /// <param name="chunkSize">The size of the memory block representing single segment within sequence.</param>
 /// <param name="allocator">The allocator used to rent the segments.</param>
 /// <exception cref="ArgumentOutOfRangeException"><paramref name="chunkSize"/> is less than or equal to zero.</exception>
 public SequenceBuilder(int chunkSize, MemoryAllocator <T>?allocator = null)
     : base(chunkSize, SparseBufferGrowth.Linear, allocator)
 {
 }
Esempio n. 9
0
 /// <summary>
 /// Initializes a new builder with automatically selected
 /// chunk size.
 /// </summary>
 /// <param name="pool">Memory pool used to allocate memory chunks.</param>
 public SparseBufferWriter(MemoryPool <T> pool)
 {
     chunkSize = -1;
     allocator = pool.ToAllocator();
 }
Esempio n. 10
0
 /// <summary>
 /// Initializes a new builder with the specified size of memory block.
 /// </summary>
 /// <param name="chunkSize">The size of the memory block representing single segment within sequence.</param>
 /// <param name="allocator">The allocator used to rent the segments.</param>
 /// <exception cref="ArgumentOutOfRangeException"><paramref name="chunkSize"/> is less than or equal to zero.</exception>
 public SequenceBuilder(int chunkSize, MemoryAllocator <T>?allocator = null)
     : base(chunkSize, allocator)
 {
 }