libusual
0.1
|
Slab allocator for same-size objects. More...
Typedefs | |
typedef void(* | slab_init_fn )(void *obj) |
Signature for object init function. | |
typedef void(* | slab_stat_fn )(void *arg, const char *slab_name, unsigned size, unsigned free, unsigned total) |
Signature for stat info callback. | |
Functions | |
struct Slab * | slab_create (const char *name, unsigned obj_size, unsigned align, slab_init_fn init_func, CxMem *cx) |
Create new slab context for specific size. | |
void | slab_destroy (struct Slab *slab) |
Free whole context. | |
void * | slab_alloc (struct Slab *slab) _MALLOC _MUSTCHECK |
Allocate single object from slab cache. | |
void | slab_free (struct Slab *slab, void *obj) |
Release single object back. | |
int | slab_total_count (const struct Slab *slab) |
Return sum of free and used objects. | |
int | slab_free_count (const struct Slab *slab) |
Return number of free objects in cache. | |
int | slab_active_count (const struct Slab *slab) |
Return number of used objects. | |
void | slab_stats (slab_stat_fn cb_func, void *cb_arg) |
Run stat info callback on all slabs. |
Slab allocator for same-size objects.
Basic behaviour:
ATM custom 'align' larger than malloc() alignment does not work.
typedef void(* slab_init_fn)(void *obj) |
Signature for object init function.
typedef void(* slab_stat_fn)(void *arg, const char *slab_name, unsigned size, unsigned free, unsigned total) |
Signature for stat info callback.
struct Slab* slab_create | ( | const char * | name, |
unsigned | obj_size, | ||
unsigned | align, | ||
slab_init_fn | init_func, | ||
CxMem * | cx | ||
) | [read] |
Create new slab context for specific size.
void slab_destroy | ( | struct Slab * | slab | ) |
Free whole context.
void* slab_alloc | ( | struct Slab * | slab | ) |
Allocate single object from slab cache.
void slab_free | ( | struct Slab * | slab, |
void * | obj | ||
) |
Release single object back.
int slab_total_count | ( | const struct Slab * | slab | ) |
Return sum of free and used objects.
int slab_free_count | ( | const struct Slab * | slab | ) |
Return number of free objects in cache.
int slab_active_count | ( | const struct Slab * | slab | ) |
Return number of used objects.
void slab_stats | ( | slab_stat_fn | cb_func, |
void * | cb_arg | ||
) |
Run stat info callback on all slabs.