/// <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; }
internal void Realloc(MemoryAllocator <T>?allocator, int length) { owner.Dispose(); owner = allocator.Invoke(length, false); }
internal PooledMemoryChunk(MemoryAllocator <T>?allocator, int length, MemoryChunk?previous = null) : base(previous) { owner = allocator.Invoke(length, false); }
/// <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(); }
internal BufferedStreamWriter(Stream output, MemoryAllocator <byte> allocator) { this.output = output; this.allocator = allocator; }
public static void ArrayAllocation() { using var owner = MemoryAllocator.CreateArrayAllocator <int>().Invoke(4, false); Equal(4, owner.Length); }
/// <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, }; } }
/// <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) { }
/// <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(); }
/// <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) { }