Buffer.this

Creates a buffer specifying the chunk size. This should be the default constructor for re-used buffers and input buffers.

  1. this(size_t chunk)
    class Buffer
    pure nothrow @trusted @nogc
    this
    (
    size_t chunk
    )
  2. this(T[] data)

Examples

t {
		
		Buffer buffer = new Buffer(8);
		
		// 8 bytes allocated by the constructor
		assert(buffer.capacity == 8);
		
		// writing 4 bytes does not alter the capacity
		buffer.write(0);
		assert(buffer.capacity == 8);
		
		// writing 8 bytes requires a new allocation (because 4 + 8 is
		// higher than the current capacity of 8).
		// The new capacity is rounded up to the nearest multiple of the chunk size.
		buffer.write(0L);
		assert(buffer.capacity == 16);
	

Meta