Function rbufd

Create a ring buffer to manage the data from the given source, and wrap into an iopipe.

auto rbufd(T, ulong optimalReadSize = 8 * 1024 / T.sizeof, Source) (
  Source dev
)
if (hasMember!(Source, "read") && is(typeof(dev.read(T[].init)) == size_t));

auto rbufd(T, ulong optimalReadSize = 8 * 1024 / T.sizeof)();

The iopipe RingBuffer type uses virtual memory mapping to have the same segment of data mapped to consecutive addresses. This allows true zero-copy usage. However, it does require use of resources that may possibly be limited, so you may want to justify that it's needed before using instead of bufd.

Note also that a RingBuffer is not copyable (its destructor will unmap the memory), so this must use RefCounted to properly work.

Parameters

NameDescription
T The type of element to allocate with the allocator
Source The type of the input stream. This must have a function read that can read into the buffer's window.
dev The input stream to use. If not specified, then a NullDev source is assumed.

Returns

An iopipe that uses a RingBuffer to read data from the given device source.