![]() |
FD.io VPP
v17.01.1-3-gc6833f8
Vector Packet Processing
|
Fixed length block allocator. More...
Include dependency graph for pool.h:
This graph shows which files directly or indirectly include this file: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_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_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... | |
Functions | |
| static pool_header_t * | pool_header (void *v) |
| Get pool header from user pool pointer. More... | |
| 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_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.
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_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 | |||
| ) |
|
inlinestatic |
|
inlinestatic |
|
inlinestatic |
|
inlinestatic |
|
inlinestatic |