Go to the source code of this file.
◆ objpool_iterate_cb
| typedef bool(* objpool_iterate_cb) (void *data, void *arg) |
◆ objpool_alloc()
| void * objpool_alloc |
( |
struct objpool_head * | head, |
|
|
size_t | size, |
|
|
uint32_t | flags ) |
Allocate memory tracked as part of an object pool.
- Parameters
-
| head | Pointer to the object pool head. |
| size | Size in bytes of memory blocks to allocate. |
| flags | Memory allocation flags. |
- Returns
- a pointer to the allocated memory on success, NULL on failure.
Allocate a memory block of size bytes. size is used upon the first invocation to allocate memory on the heap, all consequent allocations with the same head must use the same size value. First allocation with an empty head allocates 2 blocks. After both blocks are taken and a third one is requested, the next call allocates 4 blocks, then 8, 16 and 32. After that 32 blocks are allocated every time. Note, that by design allocated blocks are never freed. See more below. TODO: flags are currently only used when allocating new object sets. Should add a check that they're consistent with already allocated objects.
◆ objpool_free()
| int objpool_free |
( |
struct objpool_head * | head, |
|
|
void * | data ) |
Return a block to the object pool.
- Parameters
-
| head | Pointer to the object pool head. |
| data | Pointer to the object to return (can be NULL) |
- Returns
- 0 on success or a negative error code.
Return a block to the object pool. Memory is never freed by design, unused blocks are kept in the object pool for future re-use.
◆ objpool_iterate()
Iterate over object pool entries until stopped.
- Parameters
-
| head | Pointer to the object pool head. |
| cb | Callback function |
| arg | Callback function argument |
- Returns
- 0 on success or a negative error code.
Call the callback function for each entry in the pool, until it returns true. If the callback never returns true, return an error.
◆ objpool_prune()
Free all of the object pool memory.
- Parameters
-
| head | Pointer to the object pool head. |