H:/Class/11756/HLab/sphinxbase-0.4/src/libsphinxbase/util/ckd_alloc.c File Reference

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#include <stdarg.h>
#include "ckd_alloc.h"
#include "err.h"

Functions

jmp_buf * ckd_set_jump (jmp_buf *env, int abort)
void ckd_fail (char *format,...)
void * __ckd_calloc__ (size_t n_elem, size_t elem_size, const char *caller_file, int caller_line)
void * __ckd_malloc__ (size_t size, const char *caller_file, int caller_line)
void * __ckd_realloc__ (void *ptr, size_t new_size, const char *caller_file, int caller_line)
char * __ckd_salloc__ (const char *orig, const char *caller_file, int caller_line)
void * __ckd_calloc_2d__ (size_t d1, size_t d2, size_t elemsize, const char *caller_file, int caller_line)
void ckd_free (void *ptr)
void ckd_free_2d (void *tmpptr)
void * __ckd_calloc_3d__ (size_t d1, size_t d2, size_t d3, size_t elemsize, const char *caller_file, int caller_line)
void ckd_free_3d (void *inptr)
void * __ckd_alloc_3d_ptr (size_t d1, size_t d2, size_t d3, void *store, size_t elem_size, char *file, int line)
void * __ckd_alloc_2d_ptr (size_t d1, size_t d2, void *store, size_t elem_size, char *file, int line)

Function Documentation

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.

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.

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.

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.

void* __ckd_calloc__ ( size_t  n_elem,
size_t  elem_size,
const char *  caller_file,
int  caller_line 
)
void* __ckd_malloc__ ( size_t  size,
const char *  caller_file,
int  caller_line 
)
void* __ckd_realloc__ ( void *  ptr,
size_t  new_size,
const char *  caller_file,
int  caller_line 
)
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.

void ckd_fail ( char *  format,
  ... 
)

Fail (with a message) according to behaviour specified by ckd_set_jump().

void ckd_free ( void *  ptr  ) 

Test and free a 1-D array

void ckd_free_2d ( void *  ptr  ) 

Free a 2-D array (ptr) previously allocated by ckd_calloc_2d

void ckd_free_3d ( void *  ptr  ) 

Free a 3-D array (ptr) previously allocated by ckd_calloc_3d

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:
env Pointer to a jmp_buf initialized with setjmp(), or NULL to remove a previously set jump target.
abort If 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.
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Defines
Generated on Sat May 8 14:21:41 2010 for HLab by  doxygen 1.6.3