Buffers
Capy’s buffer system enables efficient I/O operations through lightweight memory views, scatter/gather I/O, and growable storage containers.
Overview
Buffers are the foundation of all I/O in Capy. They represent regions of memory that can be read from or written to, enabling zero-copy data transfer and platform-agnostic I/O algorithms.
Quick Example
#include <boost/capy/buffers.hpp>
#include <boost/capy/buffers/make_buffer.hpp>
#include <boost/capy/read.hpp>
#include <boost/capy/write.hpp>
using namespace boost::capy;
task<void> echo(ReadStream auto& in, WriteStream auto& out)
{
char buffer[4096];
for (;;)
{
auto [ec1, n] = co_await in.read_some(make_buffer(buffer));
if (ec1 == cond::eof)
break;
if (ec1.failed())
co_return;
auto [ec2, _] = co_await write(out, make_buffer(buffer, n));
if (ec2.failed())
co_return;
}
}
Topics
| Topic | Description |
|---|---|
Why buffers exist and how they enable efficient I/O |
|
|
|
Scatter/gather I/O with multiple buffers |
|
|
|
Growable buffers with producer/consumer model |
Key Types
| Type | Purpose |
|---|---|
|
Read-only view of contiguous bytes |
|
Writable view of contiguous bytes |
|
Growable contiguous buffer |
|
Ring buffer for streaming |
|
Adapter for |
|
Adapter for |
Key Concepts
| Concept | Description |
|---|---|
|
Range of read-only buffers |
|
Range of writable buffers |
|
Resizable buffer with prepare/commit semantics |
|
Safe parameter passing for coroutines |
Headers
| Header | Contents |
|---|---|
|
Core buffer types and concepts |
|
|
|
|
|
Incremental buffer consumption |
|
Contiguous dynamic buffer |
|
Ring buffer implementation |
|
String adapter |
|
Vector adapter |