MMgr v2.3.0
Zero-heap memory manager in C11. One borrowed buffer, carved by asserted offset.
Loading...
Searching...
No Matches
memoria_vector.h File Reference

A vector behind a const token, with its elements in one movable cell, and its calls on many threads at once. More...

Go to the source code of this file.

Data Structures

struct  VectorRecord
 The record of one vector, which its token names. More...
struct  MemoriaVectorCfg
 Arguments for every mmgr_vector_ entry, each reading only the members it needs. More...
struct  MemoriaVectorNs
 Type of the vector dispatch table. More...

Macros

#define MMGR_VECTOR_CHUNK_BYTES
 Bytes of the buffer on the stack that a growth copies the elements through, which a build may set before it includes this header.
#define MMGR_VECTOR_CLAIM_BITS
 Asserts that a growth copies at least one byte a chunk.
#define MMGR_VECTOR_CLAIM_WORDS(limit_)
 The words of claim bits for a ceiling of limit_ elements.
#define MemoriaVector(name_, element_, limit_, owner_)
 Declares a vector of element_ with a ceiling of limit_ elements, its cell counted to owner_.
#define MMGR_VECTOR_THROUGH(guard_)
 The movable entries of a guard, as the members of a MemoriaVectorCfg.

Functions

EMBED_HOST_DEVICE embed_bool mmgr_vector_at (const MemoriaVectorCfg *args)
 Copies the element at args->index to args->dst.
EMBED_HOST_DEVICE embed_bool mmgr_vector_set (const MemoriaVectorCfg *args)
 Copies the element at args->src to args->index.
EMBED_HOST_DEVICE embed_bool mmgr_vector_push_back (const MemoriaVectorCfg *args)
 Appends the element at args->src.
EMBED_HOST_DEVICE embed_bool mmgr_vector_pop_back (const MemoriaVectorCfg *args)
 Removes the last element and copies it to args->dst.
EMBED_HOST_DEVICE size_t mmgr_vector_size (const MemoriaVectorCfg *args)
 Returns the count of elements.
EMBED_HOST_DEVICE embed_bool mmgr_vector_release (const MemoriaVectorCfg *args)
 Gives the cell of the vector back, and leaves the vector with no element.

Variables

static const MemoriaVectorNs memoria_vector
 Dispatch table instance named memoria_vector, whose members are the mmgr_vector_ entries.

Detailed Description

A vector behind a const token, with its elements in one movable cell, and its calls on many threads at once.

Author
dstroy0 (Douglas Quigg) dquig.nosp@m.g123.nosp@m.@gmai.nosp@m.l.co.nosp@m.m
Date
2026-11-23
Note
The caller holds a guard and the token of the vector. The token is the address of the record, a const pointer that the linker resolves. The record holds the count, the movable cell of the elements, the capacity and one claim bit an element. No call gives back the cell or an address in it.
Each call goes through the movable entries of the guard, which MMGR_VECTOR_THROUGH names. An element moves between the cell and a buffer of the caller, and never in place.
at and set claim the bit of their element, then read the count. A push claims the bit of the element at the count, writes it, and one CAS takes the count up. A pop claims the bit of the last element, and one CAS takes the count down. LocusCarcerum/ConcurrentVector.lean proves these calls linearizable.
A growth claims each bit below the count. It copies the elements a chunk at a time through a buffer on the stack, and it gives the old cell back. LocusCarcerum/Vector.lean proves that a relocation changes nothing that the caller can see.
The ceiling bounds the capacity, and the vector refuses a push at the ceiling. A growth that the cellblock cannot meet refuses its push too.

Definition in file memoria_vector.h.