listelem_alloc.h File Reference

Fast memory allocator for uniformly sized objects. More...

`#include <stdlib.h>`
`#include <sphinxbase/sphinxbase_export.h>`
`#include <sphinxbase/prim_type.h>`

Go to the source code of this file.

## Macros

#define | listelem_malloc(le) __listelem_malloc__((le),__FILE__,__LINE__)
| Allocate a list element and return pointer to it.
#define | listelem_malloc_id(le, oid) __listelem_malloc_id__((le),__FILE__,__LINE__,(oid))
| Allocate a list element, returning a unique identifier.
#define | listelem_free(le, el) __listelem_free__((le),(el),__FILE__,__LINE__)
| Macro of listelem_free

## Typedefs

typedef struct listelem_alloc_s | listelem_alloc_t
| List element allocator object.

## Functions

SPHINXBASE_EXPORT listelem_alloc_t * | listelem_alloc_init (size_t elemsize)
| Initialize and return a list element allocator.
SPHINXBASE_EXPORT void | listelem_alloc_free (listelem_alloc_t *le)
| Finalize and release all memory associated with a list element allocator.
SPHINXBASE_EXPORT void * | __listelem_malloc__ (listelem_alloc_t *le, char *file, int line)
SPHINXBASE_EXPORT void * | __listelem_malloc_id__ (listelem_alloc_t *le, char *file, int line, int32 *out_id)
SPHINXBASE_EXPORT void * | listelem_get_item (listelem_alloc_t *le, int32 id)
| Retrieve a list element by its identifier.
SPHINXBASE_EXPORT void | __listelem_free__ (listelem_alloc_t *le, void *elem, char *file, int line)
| Free list element of given size.
SPHINXBASE_EXPORT void | listelem_stats (listelem_alloc_t *le)
| Print number of allocation, numer of free operation stats.

## Detailed Description

Fast memory allocator for uniformly sized objects.

Author
  M K Ravishankar rkm@c.nosp@m.s.cm.nosp@m.u.edu

Definition in file listelem_alloc.h.

## Macro Definition Documentation

## listelem_free

#define listelem_free | ( |  | le,
|  |  | el
| ) |  | __listelem_free__((le),(el),__FILE__,__LINE__)

Macro of listelem_free

Definition at line 112 of file listelem_alloc.h.

## listelem_malloc

#define listelem_malloc | ( |  | le | ) | __listelem_malloc__((le),__FILE__,__LINE__)

Allocate a list element and return pointer to it.

Definition at line 86 of file listelem_alloc.h.

## listelem_malloc_id

#define listelem_malloc_id | ( |  | le,
|  |  | oid
| ) |  | __listelem_malloc_id__((le),__FILE__,__LINE__,(oid))

Allocate a list element, returning a unique identifier.

Definition at line 95 of file listelem_alloc.h.

## Typedef Documentation

## listelem_alloc_t

typedef struct listelem_alloc_s listelem_alloc_t

List element allocator object.

Definition at line 65 of file listelem_alloc.h.

## Function Documentation

## __listelem_free__()

SPHINXBASE_EXPORT void __listelem_free__ | ( | listelem_alloc_t * | le,
|  | void * | elem,
|  | char * | file,
|  | int | line
| ) |  |

Free list element of given size.

Definition at line 257 of file listelem_alloc.c.

References __listelem_free__(), and listelem_alloc_s::freelist.

Referenced by __listelem_free__().

## __listelem_malloc__()

SPHINXBASE_EXPORT void * __listelem_malloc__ | ( | listelem_alloc_t * | le,
|  | char * | file,
|  | int | line
| ) |  |

Definition at line 173 of file listelem_alloc.c.

## __listelem_malloc_id__()

SPHINXBASE_EXPORT void * __listelem_malloc_id__ | ( | listelem_alloc_t * | le,
|  | char * | file,
|  | int | line,
|  | int32 * | out_id
| ) |  |

Definition at line 190 of file listelem_alloc.c.

## listelem_alloc_free()

SPHINXBASE_EXPORT void listelem_alloc_free | ( | listelem_alloc_t * | le | ) |

Finalize and release all memory associated with a list element allocator.

Definition at line 121 of file listelem_alloc.c.

References listelem_alloc_s::blocks, listelem_alloc_s::blocksize, ckd_free(), glist_free(), gnode_ptr, and listelem_alloc_free().

Referenced by listelem_alloc_free().

## listelem_alloc_init()

SPHINXBASE_EXPORT listelem_alloc_t * listelem_alloc_init | ( | size_t | elemsize | ) |

Initialize and return a list element allocator.

Definition at line 87 of file listelem_alloc.c.

References listelem_alloc_s::blk_alloc, listelem_alloc_s::blocks, ckd_calloc, ckd_free(), E_ERROR, E_WARN, listelem_alloc_s::elemsize, listelem_alloc_s::freelist, and listelem_alloc_init().

Referenced by listelem_alloc_init().

## listelem_get_item()

SPHINXBASE_EXPORT void * listelem_get_item | ( | listelem_alloc_t * | le,
|  | int32 | id
| ) |  |

Retrieve a list element by its identifier.

Definition at line 233 of file listelem_alloc.c.

References listelem_alloc_s::blocks, E_ERROR, listelem_alloc_s::elemsize, gnode_ptr, and listelem_get_item().

Referenced by listelem_get_item().

## listelem_stats()

SPHINXBASE_EXPORT void listelem_stats | ( | listelem_alloc_t * | le | ) |

Print number of allocation, numer of free operation stats.

Definition at line 273 of file listelem_alloc.c.

References listelem_alloc_s::blocks, listelem_alloc_s::blocksize, E_INFO, listelem_alloc_s::elemsize, listelem_alloc_s::freelist, gnode_ptr, and listelem_stats().

Referenced by listelem_stats().