memory.h

00001 /* 
00002  * Copyright (C) 2005 iptelorg GmbH
00003  *
00004  * This file is part of ser, a free SIP server.
00005  *
00006  * ser is free software; you can redistribute it and/or modify
00007  * it under the terms of the GNU General Public License as published by
00008  * the Free Software Foundation; either version 2 of the License, or
00009  * (at your option) any later version
00010  *
00011  * For a license to use the ser software under conditions
00012  * other than those described here, or to purchase support for this
00013  * software, please contact iptel.org by e-mail at the following addresses:
00014  *    info@iptel.org
00015  *
00016  * ser is distributed in the hope that it will be useful,
00017  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00018  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00019  * GNU General Public License for more details.
00020  *
00021  * You should have received a copy of the GNU General Public License
00022  * along with this program; if not, write to the Free Software
00023  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00024  */
00025 
00026 #ifndef __CDS_MEMORY_H
00027 #define __CDS_MEMORY_H
00028 
00029 /* #define TRACE_CDS_MEMORY */
00030 
00031 #ifdef __cplusplus
00032 extern "C" {
00033 #endif
00034 
00046 /* typedef void*(*cds_malloc_func)(unsigned int size);
00047 typedef void(*cds_free_func)(void *ptr);
00048 
00049 extern cds_malloc_func cds_malloc;
00050 extern cds_free_func cds_free;
00051 
00052 void cds_set_memory_functions(cds_malloc_func _malloc, cds_free_func _free); */
00053 
00090 #ifdef TRACE_CDS_MEMORY
00091 
00093 void *debug_malloc(int size, const char *file, int line);
00094 
00096 void debug_free(void *block, const char *file, int line);
00097 
00100 void *debug_malloc_ex(unsigned int size);
00101 
00104 void debug_free_ex(void *block);
00105 
00106 /* \internal Helper function for debugging - shows some debugging information about
00107  * memory allocations (currently only the number of allocated blocks). */
00108 void cds_memory_trace(char *dst, int dst_len);
00109 
00112 void cds_memory_trace_init();
00113 
00114 #define cds_malloc(s)   debug_malloc(s,__FILE__, __LINE__)
00115 #define cds_free(p)             debug_free(p,__FILE__, __LINE__)
00116 #define cds_free_ptr    debug_free_ex
00117 #define cds_malloc_ptr  debug_malloc_ex
00118 #define cds_malloc_pkg(s)       debug_malloc(s,__FILE__, __LINE__)
00119 #define cds_free_pkg(p)         debug_free(p,__FILE__, __LINE__)
00120 
00121 #else /* !TRACE */
00122 
00123 #ifdef SER
00124 
00125 #include <mem/mem.h>
00126 #include <mem/shm_mem.h>
00127 
00128 void* shm_malloc_x(unsigned int size);
00129 void shm_free_x(void *ptr);
00130 
00131 #define cds_malloc(s)   shm_malloc(s)
00132 #define cds_free(p)             shm_free(p)
00133 #define cds_malloc_ptr  shm_malloc_x
00134 #define cds_free_ptr    shm_free_x
00135 #define cds_malloc_pkg(s)       pkg_malloc(s)
00136 #define cds_free_pkg(p)         pkg_free(p)
00137 
00138 #else /* !SER */
00139 
00140 #include <stdlib.h>
00141 
00142 #define cds_malloc(s)   malloc(s)
00143 #define cds_free(p)             free(p)
00144 #define cds_malloc_ptr  malloc
00145 #define cds_free_ptr    free
00146 #define cds_malloc_pkg(s)       malloc(s)
00147 #define cds_free_pkg(p)         free(p)
00148 
00149 #endif /* !SER */
00150 
00151 #endif /* !TRACE_CDS_MEMORY */
00152 
00153 #ifdef __cplusplus
00154 }
00155 #endif
00156 
00160 #endif
00161