allocrus.h File Reference

This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  ILLbigchunkptr
struct  ILLptrworld

Defines

#define ILL_BIGCHUNK   ((int) ((1<<16) - sizeof (ILLbigchunkptr) - 16))
#define ILL_IFFREE(object, type)
#define ILL_PTRWORLD_ALLOC_ROUTINE(type, ptr_alloc_r, ptr_bulkalloc_r)
#define ILL_PTRWORLD_FREE_ROUTINE(type, ptr_free_r)
#define ILL_PTRWORLD_LEAKS_ROUTINE(type, ptr_leaks_r, field, fieldtype)
#define ILL_PTRWORLD_LIST_ROUTINES(type, entrytype, ptr_alloc_r, ptr_bulkalloc_r, ptr_free_r, ptr_listadd_r, ptr_listfree_r)
#define ILL_PTRWORLD_LISTADD_ROUTINE(type, entrytype, ptr_listadd_r, ptr_alloc_r)
#define ILL_PTRWORLD_LISTFREE_ROUTINE(type, ptr_listfree_r, ptr_free_r)
#define ILL_PTRWORLD_ROUTINES(type, ptr_alloc_r, ptr_bulkalloc_r, ptr_free_r)
#define ILL_UTIL_SAFE_MALLOC(nnum, type, varname)

Functions

void ** ILLptrworld_add (ILLptrworld *world)
void ** ILLptrworld_delete (ILLptrworld *world)
void ** ILLptrworld_init (ILLptrworld *world)
void * ILLutil_allocrus (size_t size)
ILLbigchunkptrILLutil_bigchunkalloc (void)
void ** ILLutil_bigchunkfree (ILLbigchunkptr *bp)
void ** ILLutil_freerus (void *p)
void ** ILLutil_reallocrus (void *ptr, size_t size)
int ILLutil_reallocrus_count (void **pptr, int count, size_t size)
int ILLutil_reallocrus_scale (void **pptr, int *pnnum, int count, double scale, size_t size)

Variables

int ILLTRACE_MALLOC


Define Documentation

#define ILL_BIGCHUNK   ((int) ((1<<16) - sizeof (ILLbigchunkptr) - 16))

Definition at line 187 of file allocrus.h.

#define ILL_IFFREE ( object,
type   ) 

Value:

{                                           \
    if ((object)) {                                                        \
       ILLutil_freerus ((void *) (object));                                 \
       object = (type *) NULL;                                             \
    }}

Definition at line 56 of file allocrus.h.

#define ILL_PTRWORLD_ALLOC_ROUTINE ( type,
ptr_alloc_r,
ptr_bulkalloc_r   ) 

Value:

\
static int ptr_bulkalloc_r (ILLptrworld *world, int nalloc)                   \
{                                                                            \
    ILLbigchunkptr *bp;                                                       \
    int i;                                                                   \
    int count = ILL_BIGCHUNK / sizeof ( type );                               \
    type *p;                                                                 \
                                                                             \
    while (nalloc > 0) {                                                     \
        bp = ILLutil_bigchunkalloc ();                                        \
        if (bp == (ILLbigchunkptr *) NULL) {                                  \
            fprintf (stderr, "ptr alloc failed\n");                          \
            return 1;                                                        \
        }                                                                    \
        bp->next = world->chunklist ;                                        \
        world->chunklist = bp;                                               \
                                                                             \
        p = ( type * ) bp->this_one;                                         \
        for (i=count-2; i>=0; i--) {                                         \
            p[i].next = &p[i+1];                                             \
        }                                                                    \
        p[count - 1].next = (type *) world->freelist;                        \
        world->freelist = (void *) p;                                        \
        nalloc -= count;                                                     \
    }                                                                        \
    return 0;                                                                \
}                                                                            \
                                                                             \
static type *ptr_alloc_r (ILLptrworld *world)                                 \
{                                                                            \
    type *p;                                                                 \
                                                                             \
    if (world->freelist == (void *) NULL) {                                  \
        if (ptr_bulkalloc_r (world, 1)) {                                    \
            fprintf (stderr, "ptr alloc failed\n");                          \
            return ( type * ) NULL;                                          \
        }                                                                    \
    }                                                                        \
    p = (type *) world->freelist ;                                           \
    world->freelist = (void *) p->next;                                      \
                                                                             \
    return p;                                                                \
}

Definition at line 62 of file allocrus.h.

#define ILL_PTRWORLD_FREE_ROUTINE ( type,
ptr_free_r   ) 

Value:

\
static void ptr_free_r (ILLptrworld *world, type *p)                          \
{                                                                            \
    p->next = (type *) world->freelist ;                                     \
    world->freelist = (void *) p;                                            \
}

Definition at line 107 of file allocrus.h.

#define ILL_PTRWORLD_LEAKS_ROUTINE ( type,
ptr_leaks_r,
field,
fieldtype   ) 

Value:

\
static int ptr_leaks_r (ILLptrworld *world, int *total, int *onlist)          \
{                                                                            \
    int count = ILL_BIGCHUNK / sizeof ( type );                               \
    int duplicates = 0;                                                      \
    type * p;                                                                \
    ILLbigchunkptr *bp;                                                       \
                                                                             \
    *total = 0;                                                              \
    *onlist = 0;                                                             \
                                                                             \
    for (bp = world->chunklist ; bp; bp = bp->next)                          \
        (*total) += count;                                                   \
                                                                             \
    for (p = (type *) world->freelist ; p; p = p->next) {                    \
        (*onlist)++;                                                         \
        p-> field = ( fieldtype ) 0;                                         \
    }                                                                        \
    for (p = (type *) world->freelist ; p; p = p->next) {                    \
        if ((unsigned long) p-> field == (unsigned long) (size_t) 1)                           \
            duplicates++;                                                    \
        else                                                                 \
            p-> field = ( fieldtype ) (size_t) 1;                            \
    }                                                                        \
    if (duplicates) {                                                        \
        fprintf (stderr, "WARNING: %d duplicates on ptr free list \n",       \
                 duplicates);                                                \
    }                                                                        \
    return *total - *onlist;                                                 \
}

Definition at line 146 of file allocrus.h.

#define ILL_PTRWORLD_LIST_ROUTINES ( type,
entrytype,
ptr_alloc_r,
ptr_bulkalloc_r,
ptr_free_r,
ptr_listadd_r,
ptr_listfree_r   ) 

Value:

ILL_PTRWORLD_ROUTINES (type, ptr_alloc_r, ptr_bulkalloc_r, ptr_free_r)        \
ILL_PTRWORLD_LISTADD_ROUTINE (type, entrytype, ptr_listadd_r, ptr_alloc_r)    \
ILL_PTRWORLD_LISTFREE_ROUTINE (type, ptr_listfree_r, ptr_free_r)

Definition at line 182 of file allocrus.h.

#define ILL_PTRWORLD_LISTADD_ROUTINE ( type,
entrytype,
ptr_listadd_r,
ptr_alloc_r   ) 

Value:

\
static int ptr_listadd_r (type **list, entrytype x, ILLptrworld *world)       \
{                                                                            \
    if (list != (type **) NULL) {                                            \
        type *p = ptr_alloc_r (world);                                       \
                                                                             \
        if (p == (type *) NULL) {                                            \
            fprintf (stderr, "ptr list add failed\n");                       \
            return 1;                                                        \
        }                                                                    \
        p->this = x;                                                         \
        p->next = *list;                                                     \
        *list = p;                                                           \
    }                                                                        \
    return 0;                                                                \
}

Definition at line 115 of file allocrus.h.

#define ILL_PTRWORLD_LISTFREE_ROUTINE ( type,
ptr_listfree_r,
ptr_free_r   ) 

Value:

\
static void ptr_listfree_r (ILLptrworld *world, type *p)                      \
{                                                                            \
    type *next;                                                              \
                                                                             \
    while (p != (type *) NULL) {                                             \
        next = p->next;                                                      \
        ptr_free_r (world, p);                                               \
        p = next;                                                            \
    }                                                                        \
}

Definition at line 133 of file allocrus.h.

#define ILL_PTRWORLD_ROUTINES ( type,
ptr_alloc_r,
ptr_bulkalloc_r,
ptr_free_r   ) 

Value:

ILL_PTRWORLD_ALLOC_ROUTINE (type, ptr_alloc_r, ptr_bulkalloc_r)               \
ILL_PTRWORLD_FREE_ROUTINE (type, ptr_free_r)

Definition at line 178 of file allocrus.h.

#define ILL_UTIL_SAFE_MALLOC ( nnum,
type,
varname   ) 

Value:

(((ILLTRACE_MALLOC) ? printf("%s.%d: %s: ILL_UTIL_SAFE_MALLOC: %s = %d * %s\n", __FILE__, __LINE__, __DEV_FUNCTION__, #varname, nnum, #type) : 0), \
     (type *) ILLutil_allocrus (((size_t) (nnum)) * sizeof (type)))

Definition at line 47 of file allocrus.h.


Function Documentation

void* * ILLptrworld_add ( ILLptrworld world  ) 

void* * ILLptrworld_delete ( ILLptrworld world  ) 

Definition at line 267 of file allocrus.c.

void* * ILLptrworld_init ( ILLptrworld world  ) 

void* ILLutil_allocrus ( size_t  size  ) 

ILLbigchunkptr* ILLutil_bigchunkalloc ( void   ) 

Definition at line 227 of file allocrus.c.

void* * ILLutil_bigchunkfree ( ILLbigchunkptr bp  ) 

void* * ILLutil_freerus ( void *  p  ) 

void* * ILLutil_reallocrus ( void *  ptr,
size_t  size 
)

int ILLutil_reallocrus_count ( void **  pptr,
int  count,
size_t  size 
)

Definition at line 204 of file allocrus.c.

int ILLutil_reallocrus_scale ( void **  pptr,
int *  pnnum,
int  count,
double  scale,
size_t  size 
)


Variable Documentation

int ILLTRACE_MALLOC

Definition at line 112 of file allocrus.c.


Generated on Thu Mar 29 09:32:35 2012 for QSopt_ex by  doxygen 1.4.7