include/mb_tools.h File Reference

#include <stdlib.h>

Go to the source code of this file.

Defines

#define STAILQ(type)
#define STAILQ_INIT(q)
#define STAILQ_CLEAN(q)   STAILQ_INIT(q)
#define STAILQ_HEAD(q)   ((q).head)
#define STAILQ_TAIL(q)   ((q).tail)
#define STAILQ_NEXT(type, field, elm)   ((elm)->field)
#define STAILQ_INS(q, type, field, elm)
#define STAILQ_INS_TAIL(q, type, field, elm)
#define STAILQ_INS_AFTER(type, field, follow, elm)
#define STAILQ_REMOVE(q, type, field, elm)
#define DARRAY(name, type)
 Declare a DARRAY storage type.
#define DARRAY_DEFINE(name, type)
#define DARRAY_CLEAN(da)   do { (da)->num = 0; } while(0)
#define DARRAY_INIT(da)   do { (da)->num = (da)->max = 0; (da)->ds = NULL; }
#define DARRAY_DESTROY(da)   do { if((da)->ds) free((da)->ds); } while(0)
#define O_ALLOC(type)   ((type *)malloc(sizeof(type)))
#define OFFSET(type, mem)   (((void *)&((type *)NULL)->mem) - NULL)
#define MEM2OBJ(var, type, mem)   ((type *)((void *)var - OFFSET(type, mem)))
#define OFF2TYPE(obj, off, type)   (*(type *)((void *)(obj) + (off)))

Typedefs

typedef struct _elmpool elmpool_t

Functions

elmpool_telmpool_new (int elm_sz, int inc_num)
 Create a new data elements pool.
void * elmpool_elm_alloc (elmpool_t *pool)
void elmpool_elm_free (elmpool_t *pool, void *elm)
void elmpool_free (elmpool_t *pool)


Define Documentation

#define MEM2OBJ ( var,
type,
mem   )     ((type *)((void *)var - OFFSET(type, mem)))

Definition at line 133 of file mb_tools.h.

#define O_ALLOC ( type   )     ((type *)malloc(sizeof(type)))

Definition at line 130 of file mb_tools.h.

#define OFF2TYPE ( obj,
off,
type   )     (*(type *)((void *)(obj) + (off)))

Definition at line 134 of file mb_tools.h.

#define OFFSET ( type,
mem   )     (((void *)&((type *)NULL)->mem) - NULL)

Definition at line 132 of file mb_tools.h.

#define STAILQ ( type   ) 

Value:

struct {                                        \
        type *head;                             \
        type *tail;                             \
    }

Definition at line 12 of file mb_tools.h.

#define STAILQ_CLEAN (  )     STAILQ_INIT(q)

Definition at line 21 of file mb_tools.h.

#define STAILQ_HEAD (  )     ((q).head)

Definition at line 22 of file mb_tools.h.

#define STAILQ_INIT (  ) 

Value:

do {                                    \
        (q).head = (q).tail = NULL;             \
    } while(0)

Definition at line 17 of file mb_tools.h.

#define STAILQ_INS ( q,
type,
field,
elm   ) 

Value:

do {                                    \
        (elm)->field = (q).head;                \
        (q).head = elm;                         \
        if((q).tail == NULL)                    \
            (q).tail = elm;                     \
    } while(0)

Definition at line 25 of file mb_tools.h.

#define STAILQ_INS_AFTER ( type,
field,
follow,
elm   ) 

Value:

do {                                            \
        (follow)->field = (elm)->field;                 \
        (elm)->field = follow;                          \
    } while(0)

Definition at line 41 of file mb_tools.h.

#define STAILQ_INS_TAIL ( q,
type,
field,
elm   ) 

Value:

do {                                    \
        (elm)->field = NULL;                    \
        if((q).tail != NULL)                    \
            (q).tail->field = elm;              \
        (q).tail = elm;                         \
        if((q).head == NULL)                    \
            (q).head = elm;                     \
    } while(0)

Definition at line 32 of file mb_tools.h.

#define STAILQ_NEXT ( type,
field,
elm   )     ((elm)->field)

Definition at line 24 of file mb_tools.h.

#define STAILQ_REMOVE ( q,
type,
field,
elm   ) 

Value:

do {                                            \
        if((elm) == (q).head) {                         \
            (q).head = (elm)->field;                    \
            if((q).head == NULL)                        \
                (q).tail = NULL;                        \
        } else {                                        \
            type *_stailq_cur = (q).head;               \
            while(_stailq_cur != NULL &&                \
                  _stailq_cur->field != (elm))          \
                _stailq_cur = _stailq_cur->field;       \
            if(_stailq_cur != NULL) {                   \
                _stailq_cur->field = (elm)->field;      \
                if((q).tail == (elm))                   \
                    (q).tail = _stailq_cur;             \
            }                                           \
        }                                               \
    } while(0)

Definition at line 46 of file mb_tools.h.

#define STAILQ_TAIL (  )     ((q).tail)

Definition at line 23 of file mb_tools.h.


Typedef Documentation

typedef struct _elmpool elmpool_t

Definition at line 4 of file mb_tools.h.


Function Documentation

void* elmpool_elm_alloc ( elmpool_t pool  ) 

Definition at line 65 of file tools.c.

void elmpool_elm_free ( elmpool_t pool,
void *  elm 
)

Definition at line 95 of file tools.c.

void elmpool_free ( elmpool_t pool  ) 

Definition at line 100 of file tools.c.

elmpool_t* elmpool_new ( int  elm_sz,
int  inc_num 
)

Create a new data elements pool.

elmpool_t provide a pool of fixed size elements to gain better utilization of memory. It try to allocate bigger memory blocks for multiple elements.

Parameters:
elm_sz size of elements.
inc_num is number of elments to allocate every time. (>= 16)
Returns:
A elmpool or NULL for error.

Definition at line 39 of file tools.c.

SourceForge.net Logo