cmempool · Section 3
crmempool_create_from_preallocated_buffer_mp
NAME
crmempool_create_from_preallocated_buffer_mp - create ranged pool from user buffer
LIBRARY
C Collections (libccollections, -lccollections)
SYNOPSIS
#include <ccollections/cmempool.h>
crmempool *crmempool_create_from_preallocated_buffer_mp(
void *buffer,
size_t buf_size,
uint8_t smallest_size_power_of_two,
uint8_t largest_size_power_of_two,
uint8_t number_of_smallest_size_elems_power_of_two,
crmempool_fallback_policy fb_policy,
bool single_threaded,
ccol_memmgmt_procs *mmgmt_procs,
char **err);
DESCRIPTION
Creates a ranged memory pool on top of a buffer that the caller provides, so no sub-pool takes its storage from the heap. The buffer is divided into contiguous segments, one for each size tier, with the same progression of sizes and counts as in crmempool_create_mp(). It is useful on embedded systems.
PARAMETERS
buffer Pointer to preallocated buffer
buf_size Size of buffer in bytes (must match exactly
what CRMEMPOOL_DECLARE_PREALLOCATED_BUFFER
produces for the same parameters)
smallest_size_power_of_two Exponent for smallest pool size
largest_size_power_of_two Exponent for largest pool size
number_of_smallest_size_elems_power_of_two Exponent for smallest pool count
fb_policy Fallback policy for exhausted pools
single_threaded If true, take no lock
mmgmt_procs Custom memory management, or NULL
err Optional pointer that receives an error string
RETURN VALUE
Returns a pointer to the new ranged memory pool on success Returns NULL on failure
NOTES
The buffer size must match exactly what CRMEMPOOL_DECLARE_PREALLOCATED_BUFFER produces for the same parameters crmempool_destroy() does not free the buffer; its lifetime is the caller's business The pool structs themselves come from mmgmt_procs Each sub-pool calls the functions of mmgmt_procs for its dynamic fallback entries, and for its own bookkeeping of them, in the middle of an update of its own state and with its lock held when it has one. Those functions must not call back into the same ranged pool: With a lock the call can deadlock, and without one it corrupts that state. An allocator built on a pool must draw from a different pool The buffer holds every sub-pool, in segments next to each other The function returns NULL with an error if the buffer is not aligned to at least 16 bytes, the alignment that every entry of the pool is guaranteed to have. Entry 0 sits at the address of the buffer itself, so the buffer needs that alignment too, and a buffer declared with CRMEMPOOL_DECLARE_PREALLOCATED_BUFFER already has it The power-of-two limits on size and count of crmempool_create_mp() apply here as well
SEE ALSO
crmempool_create_from_preallocated_buffer(3), CRMEMPOOL_DECLARE_PREALLOCATED_BUFFER(3), crmempool_create_mp(3), crmempool_destroy(3)