MMgr v2.3.0
Zero-heap memory manager in C11. One borrowed buffer, carved by asserted offset.
Loading...
Searching...
No Matches
spatium - the fill span and the read span

Data Structures

struct  mmgr_span
 A buffer under fill: its bytes, how far the writer went, and whether it ran out. More...
struct  mmgr_cspan
 A buffer under read: its bytes, how far the reader went, and whether it ran out. More...
struct  SpatiumCfg
 Arguments for every spat call, where each call reads only the members it needs. More...
struct  SpatiumNs
 Type of the spat dispatch table. More...

Functions

EMBED_HOST_DEVICE mmgr_span mmgr_spat_from (const SpatiumCfg *args)
 Builds a fill span over args->buf, with pos at 0 and overflow clear.
EMBED_HOST_DEVICE mmgr_cspan mmgr_spat_cfrom (const SpatiumCfg *args)
 Builds a read span over args->cbuf, with pos at 0 and err clear.
EMBED_HOST_DEVICE embed_bool mmgr_spat_ok (const SpatiumCfg *args)
 Returns whether args->span has storage and has not overflowed.
EMBED_HOST_DEVICE embed_bool mmgr_spat_cok (const SpatiumCfg *args)
 Returns whether args->cspan has storage and recorded no error.
EMBED_HOST_DEVICE embed_bool mmgr_spat_has_storage (const SpatiumCfg *args)
 Returns whether args->span covers any bytes at all.
EMBED_HOST_DEVICE void mmgr_spat_reset (const SpatiumCfg *args)
 Returns the span at args->at to its start and clears its overflow.
EMBED_HOST_DEVICE mmgr_span mmgr_spat_after (const SpatiumCfg *args)
 Returns the span that begins args->count bytes into args->span.
EMBED_HOST_DEVICE mmgr_span mmgr_spat_first (const SpatiumCfg *args)
 Returns the span that covers only the first args->count bytes of args->span.
EMBED_HOST_DEVICE mmgr_cspan mmgr_spat_produced (const SpatiumCfg *args)
 Returns a read span over everything written into args->span.
EMBED_HOST_DEVICE mmgr_cspan mmgr_spat_read (const SpatiumCfg *args)
 Returns a read span over the first args->count bytes written into args->span.

Variables

static const SpatiumNs spat
 Dispatch table instance named spat, with each member set to its mmgr_spat_ function.

Detailed Description

Function Documentation

◆ mmgr_spat_from()

EMBED_HOST_DEVICE mmgr_span mmgr_spat_from ( const SpatiumCfg * args)

Builds a fill span over args->buf, with pos at 0 and overflow clear.

Parameters
[in]argsBuffer buf and its extent cap [BORROWS].
Returns
The span, by value.
Note
Asserts args->buf is not NULL and args->cap is not 0. The default MMGR_ASSERT leaves both unevaluated.
Warning
The span carries args->buf away, so that buffer must outlive every use of the span [BORROWS].

References mmgr_spat_from().

Referenced by mmgr_spat_from().

◆ mmgr_spat_cfrom()

EMBED_HOST_DEVICE mmgr_cspan mmgr_spat_cfrom ( const SpatiumCfg * args)

Builds a read span over args->cbuf, with pos at 0 and err clear.

Parameters
[in]argsBuffer cbuf and its extent cap [BORROWS].
Returns
The span, by value.
Note
cbuf and not buf. A buffer closed to writes cannot reach the fill constructor.
Takes cbuf and cap as passed over, with none of the asserts mmgr_spat_from makes. A null cbuf or a zero cap still builds, and mmgr_spat_cok is what reports the span unusable.
Warning
The span carries args->cbuf away, so that buffer must outlive every use of the span [BORROWS].

References mmgr_spat_cfrom().

Referenced by mmgr_spat_cfrom().

◆ mmgr_spat_ok()

EMBED_HOST_DEVICE embed_bool mmgr_spat_ok ( const SpatiumCfg * args)

Returns whether args->span has storage and has not overflowed.

Parameters
[in]argsSpan to test, as args->span [BORROWS].
Returns
EMBED_TRUE when the span is still usable.

References mmgr_spat_ok().

Referenced by mmgr_spat_ok().

◆ mmgr_spat_cok()

EMBED_HOST_DEVICE embed_bool mmgr_spat_cok ( const SpatiumCfg * args)

Returns whether args->cspan has storage and recorded no error.

Parameters
[in]argsRead span to test, as args->cspan [BORROWS].
Returns
EMBED_TRUE when the span is still usable.

References mmgr_spat_cok().

Referenced by mmgr_spat_cok().

◆ mmgr_spat_has_storage()

EMBED_HOST_DEVICE embed_bool mmgr_spat_has_storage ( const SpatiumCfg * args)

Returns whether args->span covers any bytes at all.

Parameters
[in]argsSpan to test, as args->span [BORROWS].
Returns
EMBED_TRUE when buf is not NULL and cap is not 0.

References mmgr_spat_has_storage().

Referenced by mmgr_spat_has_storage().

◆ mmgr_spat_reset()

EMBED_HOST_DEVICE void mmgr_spat_reset ( const SpatiumCfg * args)

Returns the span at args->at to its start and clears its overflow.

Parameters
[in,out]argsSpan to rewind, as args->at [BORROWS].
Note
The one entry that takes a span by pointer, because it is the single one that changes one.
The one call that clears overflow, which is otherwise sticky for the span's whole life.
Warning
The write through args->at has no check of its own, and so it must point at a live span. The const on the pack covers the pack, not the span at the far end of at.

References mmgr_spat_reset().

Referenced by mmgr_spat_reset().

◆ mmgr_spat_after()

EMBED_HOST_DEVICE mmgr_span mmgr_spat_after ( const SpatiumCfg * args)

Returns the span that begins args->count bytes into args->span.

Parameters
[in]argsSpan to walk, as args->span, and the bytes to skip as args->count [BORROWS].
Returns
A span over the rest, or a failed span when args->count is past cap.
Note
The span that comes back covers the same buffer args->span does [BORROWS]: a second view of those bytes and not a copy. A write through either shows in both.
An args->count of exactly cap gives an empty span that has not failed: nothing remains, but nothing went wrong either.

References mmgr_spat_after().

Referenced by mmgr_spat_after().

◆ mmgr_spat_first()

EMBED_HOST_DEVICE mmgr_span mmgr_spat_first ( const SpatiumCfg * args)

Returns the span that covers only the first args->count bytes of args->span.

Parameters
[in]argsSpan to narrow, as args->span, and the bytes to retain as args->count [BORROWS].
Returns
A span over those bytes, or a failed span when args->count is past cap.
Note
The span that comes back starts on the same byte args->span starts on [BORROWS], with a shorter cap over the same storage. A fill through one shows in a read through the other.

References mmgr_spat_first().

Referenced by mmgr_spat_first().

◆ mmgr_spat_produced()

EMBED_HOST_DEVICE mmgr_cspan mmgr_spat_produced ( const SpatiumCfg * args)

Returns a read span over everything written into args->span.

Parameters
[in]argsSpan to read back, as args->span [BORROWS].
Returns
A read span over its first pos bytes, with span's overflow as its err.
Note
The same step as mmgr_spat_read against span's own pos. That case cannot ask for more than the bytes written and so cannot fail on its own account.

References mmgr_spat_produced().

Referenced by mmgr_spat_produced().

◆ mmgr_spat_read()

EMBED_HOST_DEVICE mmgr_cspan mmgr_spat_read ( const SpatiumCfg * args)

Returns a read span over the first args->count bytes written into args->span.

Parameters
[in]argsSpan to read back, as args->span, and the bytes to cover as args->count [BORROWS].
Returns
A read span over them, marked err when args->count is past the bytes written.
Warning
The read span points at the fill span's own bytes [BORROWS], and the const on it binds this view and not the storage. A second fill of args->span moves what the reader sees, and so read it back before the next fill or copy the bytes out.

References mmgr_spat_read().

Referenced by mmgr_spat_read().

Variable Documentation

◆ spat

const SpatiumNs spat
static

Dispatch table instance named spat, with each member set to its mmgr_spat_ function.

Definition at line 222 of file spatium.h.