libusual  0.1
Typedefs | Functions
usual/slab.h File Reference

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.

Detailed Description

Slab allocator for same-size objects.

Basic behaviour:

ATM custom 'align' larger than malloc() alignment does not work.


Typedef Documentation

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.


Function Documentation

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.