Pooling IBufferWriter
07/16/2023
In the .NET 7 area some high performance APIs offer overloads for dealing with raw data via IBufferWriter<T>
. IBufferWriter is a contract for buffered writing. High performance APIs typically offer an overload of their methods with IBufferWriter<T>
along with byte[]
, Stream
or Memory<T>
. However, this is not the case for every API.
IBufferWriter<T>
offers three methods:
GetMemory()
andGetSpan()
get a piece of writable memory.Advance()
to notify the buffer writer that data has been written.
.NET 7 offers two implementations of IBufferWriter<T>
: Pipe (via PipeWriter) and ArrayBufferWriter<T>
. Pipes help to solve the problem of parsing high performance streaming data. ArrayBufferWriter<T>
offers an array-based buffering solution by implementing IBufferWriter<T>
.