FD.io VPP
v18.04-17-g3a0d853
Vector Packet Processing
|
Fixed length block allocator. More...
Go to the source code of this file.
Data Structures | |
struct | pool_header_t |
Macros | |
#define | pool_aligned_header_bytes vec_aligned_header_bytes (sizeof (pool_header_t), sizeof (void *)) |
Align pool header so that pointers are naturally aligned. More... | |
#define | pool_init_fixed(pool, max_elts) |
initialize a fixed-size, preallocated pool More... | |
#define | pool_validate_index(v, i) |
#define | pool_len(p) vec_len(p) |
Number of elements in pool vector. More... | |
#define | pool_bytes(P) (vec_bytes (P) + pool_header_bytes (P)) |
Memory usage of pool. More... | |
#define | pool_get_aligned(P, E, A) |
Allocate an object E from a pool P (general version). More... | |
#define | pool_get(P, E) pool_get_aligned(P,E,0) |
Allocate an object E from a pool P (unspecified alignment). More... | |
#define | pool_get_aligned_will_expand(P, YESNO, A) |
See if pool_get will expand the pool or not. More... | |
#define | pool_get_will_expand(P, YESNO) pool_get_aligned_will_expand(P,YESNO,0) |
#define | pool_is_free(P, E) |
Use free bitmap to query whether given element is free. More... | |
#define | pool_is_free_index(P, I) pool_is_free((P),(P)+(I)) |
Use free bitmap to query whether given index is free. More... | |
#define | pool_put(P, E) |
Free an object E in pool P. More... | |
#define | pool_put_index(p, i) |
Free pool element with given index. More... | |
#define | pool_alloc_aligned(P, N, A) |
Allocate N more free elements to pool (general version). More... | |
#define | pool_alloc(P, N) pool_alloc_aligned(P,N,0) |
Allocate N more free elements to pool (unspecified alignment). More... | |
#define | pool_free(p) (p) = _pool_free(p) |
Free a pool. More... | |
#define | pool_foreach_region(LO, HI, POOL, BODY) |
Optimized iteration through pool. More... | |
#define | pool_foreach(VAR, POOL, BODY) |
Iterate through pool. More... | |
#define | pool_elt_at_index(p, i) |
Returns pointer to element at given index. More... | |
#define | pool_next_index(P, I) |
Return next occupied pool index after i , useful for safe iteration. More... | |
#define | pool_foreach_index(i, v, body) |
Iterate pool by index. More... | |
#define | pool_flush(VAR, POOL, BODY) |
Remove all elemenets from a pool in a safe way. More... | |
Functions | |
static pool_header_t * | pool_header (void *v) |
Get pool header from user pool pointer. More... | |
void | fpool_free (void *) |
static void | pool_validate (void *v) |
Validate a pool. More... | |
static void | pool_header_validate_index (void *v, uword index) |
static uword | pool_elts (void *v) |
Number of active elements in a pool. More... | |
static uword | pool_header_bytes (void *v) |
Memory usage of pool header. More... | |
static uword | pool_free_elts (void *v) |
Queries whether pool has at least N_FREE free elements. More... | |
Fixed length block allocator.
Pools are built from clib vectors and bitmaps. Use pools when repeatedly allocating and freeing fixed-size data. Pools are fast, and avoid memory fragmentation.
Definition in file pool.h.
#define pool_aligned_header_bytes vec_aligned_header_bytes (sizeof (pool_header_t), sizeof (void *)) |
#define pool_alloc | ( | P, | |
N | |||
) | pool_alloc_aligned(P,N,0) |
#define pool_alloc_aligned | ( | P, | |
N, | |||
A | |||
) |
Allocate N more free elements to pool (general version).
#define pool_bytes | ( | P | ) | (vec_bytes (P) + pool_header_bytes (P)) |
#define pool_elt_at_index | ( | p, | |
i | |||
) |
Returns pointer to element at given index.
ASSERTs that the supplied index is valid. Even though one can write correct code of the form
use of pool_elt_at_index
is strongly suggested.
#define pool_flush | ( | VAR, | |
POOL, | |||
BODY | |||
) |
Remove all elemenets from a pool in a safe way.
VAR | each element in the pool |
POOL | The pool to flush |
BODY | The actions to perform on each element before it is returned to the pool. i.e. before it is 'freed' |
#define pool_foreach | ( | VAR, | |
POOL, | |||
BODY | |||
) |
Iterate through pool.
VAR | A variable of same type as pool vector to be used as an iterator. |
POOL | The pool to iterate across. |
BODY | The operation to perform, typically a code block. See the example below. |
This macro will call BODY
with each active pool element.
It is a bad idea to allocate or free pool element from within pool_foreach
. Build a vector of indices and dispose of them later. Or call pool_flush.
pool_foreach
is a macro, syntax errors can be difficult to find inside BODY
, let alone actual code bugs. One can temporarily split a complex pool_foreach
into a trivial pool_foreach
which builds a vector of active indices, and a vec_foreach() (or plain for-loop) to walk the active index vector. Iterate pool by index.
#define pool_foreach_region | ( | LO, | |
HI, | |||
POOL, | |||
BODY | |||
) |
Optimized iteration through pool.
LO | pointer to first element in chunk |
HI | pointer to last element in chunk |
POOL | pool to iterate across |
BODY | operation to perform |
Optimized version which assumes that BODY is smart enough to process multiple (LOW,HI) chunks. See also pool_foreach().
#define pool_get | ( | P, | |
E | |||
) | pool_get_aligned(P,E,0) |
#define pool_get_aligned | ( | P, | |
E, | |||
A | |||
) |
Allocate an object E from a pool P (general version).
First search free list. If nothing is free extend vector of objects.
#define pool_get_aligned_will_expand | ( | P, | |
YESNO, | |||
A | |||
) |
See if pool_get will expand the pool or not.
#define pool_get_will_expand | ( | P, | |
YESNO | |||
) | pool_get_aligned_will_expand(P,YESNO,0) |
#define pool_init_fixed | ( | pool, | |
max_elts | |||
) |
#define pool_is_free | ( | P, | |
E | |||
) |
Use free bitmap to query whether given element is free.
#define pool_is_free_index | ( | P, | |
I | |||
) | pool_is_free((P),(P)+(I)) |
#define pool_len | ( | p | ) | vec_len(p) |
Number of elements in pool vector.
#define pool_next_index | ( | P, | |
I | |||
) |
Return next occupied pool index after i
, useful for safe iteration.
#define pool_put | ( | P, | |
E | |||
) |
Free an object E in pool P.
#define pool_put_index | ( | p, | |
i | |||
) |
void fpool_free | ( | void * | ) |
|
inlinestatic |
|
inlinestatic |
|
inlinestatic |
|
inlinestatic |
|
inlinestatic |