BufferedOutputRange

BufferedOutputRange is a performance enhancement over writing directly to an output stream. It holds a File open for write or an OutputRange. Ouput is accumulated in an internal buffer and written to the output stream as a block.

Writing to stdout is a key use case. BufferedOutputRange is often dramatically faster than writing to stdout directly. This is especially noticable for outputs with short lines, as it blocks many writes together in a single write.

The internal buffer is written to the output stream after flushSize has been reached. This is checked at newline boundaries, when appendln is called or when put is called with a single newline character. Other writes check maxSize, which is used to avoid runaway buffers.

More...

Constructors

this
this(OutputTarget outputTarget, size_t flushSize, size_t reserveSize, size_t maxSize)
Undocumented in source.

Destructor

~this
~this()
Undocumented in source.

Members

Aliases

C
alias C = char
Undocumented in source.
C
alias C = ubyte
Undocumented in source.

Functions

append
void append(T stuff)
Undocumented in source. Be warned that the author may not have intended to support it.
appendln
bool appendln()
Undocumented in source. Be warned that the author may not have intended to support it.
appendln
bool appendln(T stuff)
Undocumented in source. Be warned that the author may not have intended to support it.
flush
void flush()
Undocumented in source. Be warned that the author may not have intended to support it.
flushIfFull
bool flushIfFull()
Undocumented in source. Be warned that the author may not have intended to support it.
flushIfMaxSize
void flushIfMaxSize()
Undocumented in source. Be warned that the author may not have intended to support it.
joinAppend
void joinAppend(InputRange inputRange, E delimiter)
Undocumented in source. Be warned that the author may not have intended to support it.
put
void put(T stuff)
Undocumented in source. Be warned that the author may not have intended to support it.

Detailed Description

BufferedOutputRange has a put method allowing it to be used a range. It has a number of other methods providing additional control.

  • this(outputStream [, flushSize, reserveSize, maxSize]) - Constructor. Takes the output stream, e.g. stdout. Other arguments are optional, defaults normally suffice.
  • append(stuff) - Append to the internal buffer.
  • appendln(stuff) - Append to the internal buffer, followed by a newline. The buffer is flushed to the output stream if is has reached flushSize.
  • appendln() - Append a newline to the internal buffer. The buffer is flushed to the output stream if is has reached flushSize.
  • joinAppend(inputRange, delim) - An optimization of append(inputRange.joiner(delim)). For reasons that are not clear, joiner is quite slow.
  • flushIfFull() - Flush the internal buffer to the output stream if flushSize has been reached.
  • flush() - Write the internal buffer to the output stream.
  • put(stuff) - Appends to the internal buffer. Acts as appendln() if passed a single newline character, '\n' or "\n".

The internal buffer is automatically flushed when the BufferedOutputRange goes out of scope.

Meta