Linear (bump) sub-allocator over a caller-supplied workspace buffer.
Each allocate() carves the next suitably aligned slice off the front of the buffer; nothing is ever freed individually. Every alignment is max(16, MEM_BASE_ADDR_ALIGN / 8, alignof(T)).
A pool made by measuring() is a sizing pool: it runs the same arithmetic over a fictitious region and reports through required_bytes() the buffer size the same call sequence needs. That is how every *_buffer_size query is computed (see workspace_bytes()).
Definition at line 30 of file mempool.hh.
#include <batchlas/util/mempool.hh>
|
inline |
A pool over byte_size bytes starting at data.
Definition at line 33 of file mempool.hh.
|
inline |
A pool over the bytes of span.
Definition at line 37 of file mempool.hh.
|
inlinestatic |
A sizing pool: an effectively unbounded, maximally aligned fictitious region.
Give a real pool required_bytes() and the same call sequence succeeds, with at most one alignment quantum to spare.
Definition at line 48 of file mempool.hh.
|
inline |
True for a pool made by measuring().
Definition at line 51 of file mempool.hh.
|
inline |
Bytes a real pool must be given for the call sequence so far to succeed.
Rounded up to the coarsest alignment the sequence asked for.
| batchlas::api_misuse | on a pool not made by measuring() |
Definition at line 59 of file mempool.hh.
|
inlinestaticconstexpr |
Alignment in bytes of an allocation of T on device.
Definition at line 69 of file mempool.hh.
|
inlinestaticconstexpr |
Bytes size elements of T occupy, rounded up to alignment<T>(); 0 for size == 0.
Definition at line 77 of file mempool.hh.
|
inlinestaticconstexpr |
allocation_size() for the Queue's device.
Definition at line 85 of file mempool.hh.
|
inlineconstexpr |
Carve size elements of T, aligned to alignment<T>(), off the front of the pool.
| T | element type |
| device | device whose alignment rule applies |
| size | number of elements; 0 returns an empty Span and consumes nothing |
| batchlas::workspace_error | if the pool has fewer than allocation_size<T>() bytes left |
Definition at line 94 of file mempool.hh.
|
inlineconstexpr |
allocate() with the Queue's device.
Definition at line 127 of file mempool.hh.
|
inline |
The still-unclaimed tail of the pool.
Lets a callee sub-allocate without the caller knowing its size up front; pair with consume() to hand back the bytes it actually took.
| batchlas::api_misuse | on a sizing pool, whose extent is fictitious |
Definition at line 134 of file mempool.hh.
|
inline |
Advance the pool by bytes (after a callee used remaining()).
| batchlas::workspace_error | if fewer than bytes remain |
Definition at line 145 of file mempool.hh.