/*======================================================================= Copyright 1993 (C) David Hinds - All Rights Reserved Source file xalloc.h Version 3.6, Updated 4/15/93 =======================================================================*/ #ifdef XALLOC_C static char ident_h[] = "@(#) xalloc.h version 3.6 (4/15/93)"; #endif /* Simplified dynamic memory allocation functions */ #define c_mnew(a, b) (b *)c_malloc((size_t)(a), sizeof(b)) #define c_cnew(a, b) (b *)c_calloc((size_t)(a), sizeof(b)) #define c_renew(a, b, c) (c *)c_realloc(a, (size_t)(b), sizeof(c)) /* 2-D arrays with fixed first dimension */ #define c_manew(a, b, c) (c(*)[a])c_malloc((size_t)(b), (a)*sizeof(c)) #define c_canew(a, b, c) (c(*)[a])c_calloc((size_t)(b), (a)*sizeof(c)) #define c_reanew(a, b, c, d) (d(*)[b])c_realloc(a, (size_t)(c), (b)*sizeof(d)) /* 2-D arrays with arbitrary dimensions */ #define c_m2new(a, b, c) (c **)m2alloc((size_t)(a), (size_t)(b), sizeof(c)) #define c_c2new(a, b, c) (c **)c2alloc((size_t)(a), (size_t)(b), sizeof(c)) #define c_free2(a) { c_free((a)[0]); c_free(a); } #ifdef _DEBUG_MEM # include "/usr/local/include/malloc_dbg.h" # define c_malloc(a, b) malloc((a)*(b)) # define c_calloc(a, b) calloc(a, b) # define c_realloc(a, b, c) realloc(a, (b)*(c)) # define c_free(a) free(a) /* # define c_malloc(a, b) d_malloc(a, b, __FILE__, __LINE__, #a, #b) # define c_calloc(a, b) d_calloc(a, b, __FILE__, __LINE__, #a, #b) # define c_realloc(a, b, c) \ d_realloc(a, b, c, __FILE__, __LINE__, #a, #b, #c) # define c_free(a) d_free(a, __FILE__, __LINE__, #a) */ #else # define c_malloc(a, b) malloc((a)*(b)) # define c_calloc(a, b) calloc(a, b) # define c_realloc(a, b, c) realloc(a, (b)*(c)) # define c_free(a) free(a) #endif /* _DEBUG_MEM */ /*=====================================================================*/ void *d_malloc(size_t n, size_t elsize, char *f, int_t l, char *a, char *b); void *d_calloc(size_t n, size_t elsize, char *f, int_t l, char *a, char *b); void *d_realloc(void *ptr, size_t n, size_t elsize, char *f, int_t l, char *a, char *b, char *c); void d_free(void *ptr, char *f, int_t l, char *a); void d_mstatus(void); void **m2alloc(size_t n1, size_t n2, size_t elsize); void **c2alloc(size_t n1, size_t n2, size_t elsize);