SphinxBase  5prealpha
ckd_alloc.h File Reference

Sphinx's memory allocation/deallocation routines. More...

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

Go to the source code of this file.

Macros

#define ckd_calloc(n, sz)   __ckd_calloc__((n),(sz),__FILE__,__LINE__)
 Macros to simplify the use of above functions. More...
 
#define ckd_malloc(sz)   __ckd_malloc__((sz),__FILE__,__LINE__)
 Macro for ckd_malloc
 
#define ckd_realloc(ptr, sz)   __ckd_realloc__(ptr,(sz),__FILE__,__LINE__)
 Macro for ckd_realloc
 
#define ckd_salloc(ptr)   __ckd_salloc__(ptr,__FILE__,__LINE__)
 Macro for ckd_salloc
 
#define ckd_calloc_2d(d1, d2, sz)   __ckd_calloc_2d__((d1),(d2),(sz),__FILE__,__LINE__)
 Macro for ckd_calloc_2d
 
#define ckd_calloc_3d(d1, d2, d3, sz)   __ckd_calloc_3d__((d1),(d2),(d3),(sz),__FILE__,__LINE__)
 Macro for ckd_calloc_3d
 
#define ckd_calloc_4d(d1, d2, d3, d4, s)   __ckd_calloc_4d__((d1), (d2), (d3), (d4), (s), __FILE__, __LINE__)
 Macro for ckd_calloc_4d
 
#define ckd_alloc_2d_ptr(d1, d2, bf, sz)   __ckd_alloc_2d_ptr((d1), (d2), (bf), (sz), __FILE__, __LINE__)
 Macro for ckd_alloc_2d_ptr
 
#define ckd_free_2d_ptr(bf)   ckd_free(bf)
 Free only the pointer arrays allocated with ckd_alloc_2d_ptr().
 
#define ckd_alloc_3d_ptr(d1, d2, d3, bf, sz)   __ckd_alloc_3d_ptr((d1), (d2), (d3), (bf), (sz), __FILE__, __LINE__)
 Macro for ckd_alloc_3d_ptr
 
#define ckd_free_3d_ptr(bf)   ckd_free_2d(bf)
 Free only the pointer arrays allocated with ckd_alloc_3d_ptr().
 

Functions

jmp_buf * ckd_set_jump (jmp_buf *env, int abort)
 Control behaviour of the program when allocation fails. More...
 
void ckd_fail (char *format,...)
 Fail (with a message) according to behaviour specified by ckd_set_jump().
 
SPHINXBASE_EXPORT void * __ckd_calloc__ (size_t n_elem, size_t elem_size, const char *caller_file, int caller_line)
 
SPHINXBASE_EXPORT void * __ckd_malloc__ (size_t size, const char *caller_file, int caller_line)
 
SPHINXBASE_EXPORT void * __ckd_realloc__ (void *ptr, size_t new_size, const char *caller_file, int caller_line)
 
SPHINXBASE_EXPORT char * __ckd_salloc__ (const char *origstr, const char *caller_file, int caller_line)
 Like strdup, except that if an error occurs it prints a diagnostic message and exits. More...
 
SPHINXBASE_EXPORT void * __ckd_calloc_2d__ (size_t d1, size_t d2, size_t elemsize, const char *caller_file, int caller_line)
 Allocate a 2-D array and return ptr to it (ie, ptr to vector of ptrs). More...
 
SPHINXBASE_EXPORT void * __ckd_calloc_3d__ (size_t d1, size_t d2, size_t d3, size_t elemsize, const char *caller_file, int caller_line)
 Allocate a 3-D array and return ptr to it. More...
 
SPHINXBASE_EXPORT void **** __ckd_calloc_4d__ (size_t d1, size_t d2, size_t d3, size_t d4, size_t elem_size, char *caller_file, int caller_line)
 Allocate a 34D array and return ptr to it. More...
 
SPHINXBASE_EXPORT void * __ckd_alloc_3d_ptr (size_t d1, size_t d2, size_t d3, void *store, size_t elem_size, char *caller_file, int caller_line)
 Overlay a 3-D array over a previously allocated storage area.
 
SPHINXBASE_EXPORT void * __ckd_alloc_2d_ptr (size_t d1, size_t d2, void *store, size_t elem_size, char *caller_file, int caller_line)
 Overlay a s-D array over a previously allocated storage area.
 
SPHINXBASE_EXPORT void ckd_free (void *ptr)
 Test and free a 1-D array.
 
SPHINXBASE_EXPORT void ckd_free_2d (void *ptr)
 Free a 2-D array (ptr) previously allocated by ckd_calloc_2d.
 
SPHINXBASE_EXPORT void ckd_free_3d (void *ptr)
 Free a 3-D array (ptr) previously allocated by ckd_calloc_3d.
 
SPHINXBASE_EXPORT void ckd_free_4d (void *ptr)
 Free a 4-D array (ptr) previously allocated by ckd_calloc_4d.
 

Detailed Description

Sphinx's memory allocation/deallocation routines.

Implementation of efficient memory allocation deallocation for multiple dimensional arrays.

Definition in file ckd_alloc.h.

Macro Definition Documentation

Function Documentation

SPHINXBASE_EXPORT void* __ckd_calloc_2d__ ( size_t  d1,
size_t  d2,
size_t  elemsize,
const char *  caller_file,
int  caller_line 
)

Allocate a 2-D array and return ptr to it (ie, ptr to vector of ptrs).

The data area is allocated in one block so it can also be treated as a 1-D array.

Definition at line 223 of file ckd_alloc.c.

SPHINXBASE_EXPORT void* __ckd_calloc_3d__ ( size_t  d1,
size_t  d2,
size_t  d3,
size_t  elemsize,
const char *  caller_file,
int  caller_line 
)

Allocate a 3-D array and return ptr to it.

The data area is allocated in one block so it can also be treated as a 1-D array.

Definition at line 265 of file ckd_alloc.c.

SPHINXBASE_EXPORT void**** __ckd_calloc_4d__ ( size_t  d1,
size_t  d2,
size_t  d3,
size_t  d4,
size_t  elem_size,
char *  caller_file,
int  caller_line 
)

Allocate a 34D array and return ptr to it.

The data area is allocated in one block so it can also be treated as a 1-D array.

Definition at line 310 of file ckd_alloc.c.

References ckd_calloc, and E_FATAL.

SPHINXBASE_EXPORT char* __ckd_salloc__ ( const char *  origstr,
const char *  caller_file,
int  caller_line 
)

Like strdup, except that if an error occurs it prints a diagnostic message and exits.

If origin in NULL the function also returns NULL.

Definition at line 205 of file ckd_alloc.c.

jmp_buf* ckd_set_jump ( jmp_buf *  env,
int  abort 
)

Control behaviour of the program when allocation fails.

Although your program is probably toast when memory allocation fails, it is also probably a good idea to be able to catch these errors and alert the user in some way. Either that, or you might want the program to call abort() so that you can debug the failed code. This function allows you to control that behaviour.

Parameters
envPointer to a jmp_buf initialized with setjmp(), or NULL to remove a previously set jump target.
abortIf non-zero, the program will call abort() when allocation fails rather than exiting or calling longjmp().
Returns
Pointer to a previously set jmp_buf, if any.

Definition at line 109 of file ckd_alloc.c.