C Collections

cmempool · Section 3

cmempool_dynamic_allocs_count

cmempool_dynamic_allocs_count - report outstanding fallback allocations

C Collections (libccollections, -lccollections)

#include <ccollections/cmempool.h>
 
size_t cmempool_dynamic_allocs_count(cmempool *mp);

Returns the number of outstanding allocations that came from the
system allocator instead of the pool's own storage. They happen only in
a pool created with fallback_to_dynamic_memory = true, and only after
the pool's elements run out.

mp                        Memory pool to query (must not be NULL)

Returns the number of outstanding fallback allocations, which is 0 for
a pool created without a fallback

A non-zero result means the pool was too small for its workload at
some point, and that elem_count should go up: Every fallback
allocation is a round trip to the system allocator, which is exactly
the cost the pool is there to avoid.
 
An entry in a thread's cache belongs to the pool, so this call never
counts one.
 
cmempool_destroy() treats an outstanding fallback allocation as a
leak and stops the process, so free every fallback entry of a pool
before you destroy it.
 
A NULL mp is a fatal error: The call prints a message and ends the
process with abort(), in every build.

Thread-safe when the pool was created with single_threaded = false.
The call takes the pool's lock, so it belongs on a cold path; don't
use it inside a hot loop.

cmempool_total_capacity(3), cmempool_used_count(3), cmempool_create_mp(3)