C Collections

cmempool · Section 3

crmempool_used_count

crmempool_used_count - get number of used entries for a size

C Collections (libccollections, -lccollections)

#include <ccollections/cmempool.h>
 
size_t crmempool_used_count(crmempool *rmp, size_t size);

Returns how many entries are allocated from the pool that would serve
the given size, without any dynamic allocation.

rmp   Ranged memory pool to query
size  Size in bytes to query (maps to a specific sub-pool)

Returns the number of entries in use for this size
Returns 0 when size is invalid

It returns 0 if size is invalid, which means 0 or above largest_size
It asserts if rmp is NULL
It rounds size up to the next power-of-two pool
Thread-safe if the pool was created with single_threaded=false
Dynamic allocations are tracked separately
 
The count is exact whenever the sub-pool is quiet. An entry parked in a
thread's cache counts as free, since nobody holds it. Under concurrent
allocation on a tier that keeps a cache for each thread, the result can
be a few entries above crmempool_total_capacity() for that size
for a short time, but never above the physical slot count that
crmempool_allocated_bytes(3) accounts for.
cmempool_total_capacity(3) explains why.

crmempool_total_capacity(3), crmempool_dynamic_allocs_count(3)