GEL  0.99
gel_mem.h
Go to the documentation of this file.
1 /*
2  * $Id$
3  *
4  * This file is part of the GEL library.
5  * Copyright (c) 2005-07, IRIT- UPS
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 2 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20  */
21 #ifndef GEL_MEM_H
22 #define GEL_MEM_H
23 
24 #include <stdio.h>
25 #include <stdlib.h>
26 
27 /* uncomment to activate */
28 /* #define GEL_DEBUG_MEM */
29 /* #define GEL_DEBUG_NOFREE */
30 
31 /* functions */
32 void *gel_debug_new(const char *file, int line, const char *t, int size);
33 void *gel_debug_newc(const char *file, int line, const char *t, int size);
34 void *gel_debug_newv(const char *file, int line, const char *t, int size, int n);
35 void *gel_debug_newvc(const char *file, int line, const char *t, int size, int n);
36 void *gel_debug_delete(const char *file, int line, void *p);
37 
38 
39 /* macros */
40 #ifndef GEL_DEBUG_MEM
41 # define new(t) ((t *)malloc(sizeof(t)))
42 # define newc(t) ((t *)calloc(sizeof(t), 1))
43 # define newv(t, n) ((t *)malloc(sizeof(t) * n))
44 # define newvc(t, n) ((t *)calloc(sizeof(t), n))
45 #else
46 # define new(t) ((t *)gel_debug_new(__FILE__, __LINE__, #t, sizeof(t)))
47 # define newc(t) ((t *)gel_debug_newc(__FILE__, __LINE__, #t, sizeof(t)))
48 # define newv(t, n) ((t *)gel_debug_newv(__FILE__, __LINE__, #t, sizeof(t), n))
49 # define newvc(t, n) ((t *)gel_debug_newvc(__FILE__, __LINE__, #t, sizeof(t), n))
50 #endif
51 
52 #ifdef GEL_DEBUG_NOFREE
53 # define delete(p)
54 #elif defined(GEL_DEBUG_MEM)
55 # define delete(p) gel_debug_delete(__FILE__, __LINE__, p)
56 #else
57 # define delete(p) free(p)
58 #endif
59 
60 #endif // GEL_MEM_H
void * gel_debug_newvc(const char *file, int line, const char *t, int size, int n)
void * gel_debug_delete(const char *file, int line, void *p)
void * gel_debug_newc(const char *file, int line, const char *t, int size)
void * gel_debug_new(const char *file, int line, const char *t, int size)
void * gel_debug_newv(const char *file, int line, const char *t, int size, int n)