GCS  0.2.3
gu_mem.h
Go to the documentation of this file.
1 // Copyright (C) 2007 Codership Oy <info@codership.com>
9 #ifndef _gu_mem_h_
10 #define _gu_mem_h_
11 
12 #include <stdlib.h>
13 #include <unistd.h>
14 
15 #ifdef __cplusplus
16 extern "C" {
17 #endif /* __cplusplus */
18 
23 void* gu_malloc_dbg (size_t size,
24  const char* file, unsigned int line);
25 void* gu_calloc_dbg (size_t nmemb, size_t size,
26  const char* file, unsigned int line);
27 void* gu_realloc_dbg (void* ptr, size_t size,
28  const char* file, unsigned int line);
29 void gu_free_dbg (void* ptr,
30  const char* file, unsigned int line);
35 void gu_mem_stats (ssize_t* total, ssize_t* allocs, ssize_t* reallocs,
36  ssize_t* deallocs);
37 
40 #ifdef DEBUG_MALLOC
41 
42 #define gu_malloc(S) gu_malloc_dbg ((S), __FILE__, __LINE__)
43 #define gu_calloc(N,S) gu_calloc_dbg ((N), (S), __FILE__, __LINE__)
44 #define gu_realloc(P,S) gu_realloc_dbg ((P), (S), __FILE__, __LINE__)
45 #define gu_free(P) gu_free_dbg ((P), __FILE__, __LINE__)
46 
47 #else /* !DEBUG_MALLOC - use standard allocation routines */
48 
49 #define gu_malloc(S) malloc ((S))
50 #define gu_calloc(N,S) calloc ((N), (S))
51 #define gu_realloc(P,S) realloc ((P), (S))
52 #define gu_free(P) free ((P))
53 
54 #endif /* DEBUG_MALLOC */
55 
57 #define GU_MALLOC(type) (type*) gu_malloc (sizeof(type))
58 #define GU_MALLOCN(N,type) (type*) gu_malloc ((N) * sizeof(type))
59 #define GU_CALLOC(N,type) (type*) gu_calloc ((N), sizeof(type))
60 #define GU_REALLOC(P,N,type) (type*) gu_realloc((P), (N) * sizeof(type))
61 
64 #ifdef __cplusplus
65 }
66 #endif /* __cplusplus */
67 
68 #endif /* _gu_mem_h_ */
void gu_mem_stats(ssize_t *total, ssize_t *allocs, ssize_t *reallocs, ssize_t *deallocs)
Definition: gu_mem.c:155