MMgr v2.3.0
Zero-heap memory manager in C11. One borrowed buffer, carved by asserted offset.
Loading...
Searching...
No Matches
memoria_vector — the vector behind a token

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

Macro Definition Documentation

◆ MMGR_VECTOR_CHUNK_BYTES

#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.

Note
A growth copies the elements a chunk of these bytes at a time, and the last chunk takes the bytes left.

Definition at line 47 of file memoria_vector.h.

◆ MMGR_VECTOR_CLAIM_BITS

#define MMGR_VECTOR_CLAIM_BITS

Asserts that a growth copies at least one byte a chunk.

The bits of one word of the claim bits of a vector: one an element.

Definition at line 54 of file memoria_vector.h.

◆ MMGR_VECTOR_CLAIM_WORDS

#define MMGR_VECTOR_CLAIM_WORDS ( limit_)

The words of claim bits for a ceiling of limit_ elements.

Parameters
[in]limit_The ceiling of the capacity.
Returns
One bit an element in whole words.

Definition at line 62 of file memoria_vector.h.

◆ MemoriaVector

#define MemoriaVector ( name_,
element_,
limit_,
owner_ )

Declares a vector of element_ with a ceiling of limit_ elements, its cell counted to owner_.

Parameters
[in]name_The token of the vector: a const pointer to its record.
[in]element_The type of one element.
[in]limit_The ceiling of the capacity, a constant above 0.
[in]owner_The identity of the owner that counts the cell, as MMGR_OWNERS declares it [BORROWS].
Note
Emits the claim bits, the record and the token as data that the linker resolves. Nothing runs before the first call, and the vector starts with no element and no cell.
The build fails where the ceiling is 0, where one cell of the ceiling passes MMGR_CARCER_BYTES_MAX, or where the alignment of the element does not divide MMGR_ALIGN_BYTES.
EMBED_PASS_MEMORY gives each pass of nvcc its own claim bits, record and token. A kernel reaches the vector in device memory, and its owner_ is the device copy of the identity.
Warning
The vector names no cellblock. Each call names the guard that it goes through, and every call on one vector must name the same guard.

Definition at line 102 of file memoria_vector.h.

◆ MMGR_VECTOR_THROUGH

#define MMGR_VECTOR_THROUGH ( guard_)

The movable entries of a guard, as the members of a MemoriaVectorCfg.

Parameters
[in]guard_The guard of a cellblock with the movable option, MinimumSecurityGuard or MaxSecurityGuard.
Note
Both guards name the four entries the same way, so either one goes here.

Definition at line 120 of file memoria_vector.h.

Function Documentation

◆ mmgr_vector_at()

EMBED_HOST_DEVICE embed_bool mmgr_vector_at ( const MemoriaVectorCfg * args)

Copies the element at args->index to args->dst.

Parameters
[in,out]argsThe vector, the guard, the index and dst [BORROWS].
Returns
EMBED_TRUE where the element came out. EMBED_FALSE where args->index is at or past the count, and nothing changes.
Note
Claims the bit of the element, reads the count, copies the element, and gives the bit back. The read of the count is the point where the call takes effect.
Warning
args->dst must be writable for one element.

References mmgr_vector_at().

Referenced by mmgr_vector_at().

◆ mmgr_vector_set()

EMBED_HOST_DEVICE embed_bool mmgr_vector_set ( const MemoriaVectorCfg * args)

Copies the element at args->src to args->index.

Parameters
[in,out]argsThe vector, the guard, the index and src [BORROWS].
Returns
EMBED_TRUE where the element went in. EMBED_FALSE where args->index is at or past the count, and nothing changes.
Note
Claims the bit of the element, reads the count, copies the element, and gives the bit back.
Warning
args->src must be readable for one element.

References mmgr_vector_set().

Referenced by mmgr_vector_set().

◆ mmgr_vector_push_back()

EMBED_HOST_DEVICE embed_bool mmgr_vector_push_back ( const MemoriaVectorCfg * args)

Appends the element at args->src.

Parameters
[in,out]argsThe vector, the guard and src [BORROWS].
Returns
EMBED_TRUE where the element went in. EMBED_FALSE where the count is at the ceiling, where a growth found no cell, or where the guard refused the write, and nothing changes.
Note
Reads the count, claims the bit of the element at the count, and reads the count again. Where the cell is full, it grows the cell. It writes the element, and one CAS takes the count up by one, which is the point where the call takes effect.
A CAS that finds another count gives the bit back and starts again, as does a claim of a held bit.
Warning
args->src must be readable for one element.

References mmgr_vector_push_back().

Referenced by mmgr_vector_push_back().

◆ mmgr_vector_pop_back()

EMBED_HOST_DEVICE embed_bool mmgr_vector_pop_back ( const MemoriaVectorCfg * args)

Removes the last element and copies it to args->dst.

Parameters
[in,out]argsThe vector, the guard and dst [BORROWS].
Returns
EMBED_TRUE where an element came out. EMBED_FALSE where the vector has no element, and nothing changes.
Note
Reads the count, and claims the bit of the last element. One CAS takes the count down by one, which is the point where the call takes effect. Then it copies the element out and gives the bit back.
Warning
args->dst must be writable for one element.
A guard other than the guard of the cell can refuse the read after the CAS. The call then answers EMBED_FALSE, and the element is gone.

References mmgr_vector_pop_back().

Referenced by mmgr_vector_pop_back().

◆ mmgr_vector_size()

EMBED_HOST_DEVICE size_t mmgr_vector_size ( const MemoriaVectorCfg * args)

Returns the count of elements.

Parameters
[in]argsThe vector [BORROWS].
Returns
The count, off one word.
Warning
The answer is only a snapshot. A push or a pop on another thread can change it before the caller acts.

References mmgr_vector_size().

Referenced by mmgr_vector_size().

◆ mmgr_vector_release()

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.

Parameters
[in,out]argsThe vector and the guard [BORROWS].
Returns
EMBED_TRUE where the cell went back or the vector had none. EMBED_FALSE where the guard refused the release of the cell.
Note
Claims every bit, from the ceiling down, so no other call reaches an element meanwhile. A later push takes a new cell.
Warning
The claims are one for each element of the ceiling. A vector with a high ceiling pays that at each release.

References mmgr_vector_release().

Referenced by mmgr_vector_release().

Variable Documentation

◆ memoria_vector

const MemoriaVectorNs memoria_vector
static

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

Definition at line 237 of file memoria_vector.h.