LALMalloc.h

Go to the documentation of this file.
00001 /*
00002 *  Copyright (C) 2007 Jolien Creighton, Kipp Cannon
00003 *
00004 *  This program is free software; you can redistribute it and/or modify
00005 *  it under the terms of the GNU General Public License as published by
00006 *  the Free Software Foundation; either version 2 of the License, or
00007 *  (at your option) any later version.
00008 *
00009 *  This program is distributed in the hope that it will be useful,
00010 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00011 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012 *  GNU General Public License for more details.
00013 *
00014 *  You should have received a copy of the GNU General Public License
00015 *  along with with program; see the file COPYING. If not, write to the
00016 *  Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston,
00017 *  MA  02111-1307  USA
00018 */
00019 
00020 /************************************ <lalVerbatim file="LALMallocHV">
00021 $Id: LALMalloc.h,v 1.4 2007/06/08 14:41:52 bema Exp $
00022 ************************************* </lalVerbatim> */
00023 
00024 /* <lalLaTeX>
00025 
00026 \section{Header \texttt{LALMalloc.h}}
00027 \label{s:LALMalloc.h}
00028 
00029 Provides standard LAL memory allocation/deallocation routines.
00030 
00031 \subsection*{Synopsis}
00032 \begin{verbatim}
00033 #include <lal/LALMalloc.h>
00034 \end{verbatim}
00035 
00036 \noindent This header covers routines that replace the standard
00037 \verb+malloc()+, \verb+calloc()+, \verb+realloc()+, and \verb+free()+.
00038 All memory allocation and deallocation in LAL should use these
00039 replacement functions.  If the \verb+NDEBUG+ flag is set at compile
00040 time, the LAL routines are \verb+#define+d to be the same as the
00041 standard C routines.
00042 
00043 \vfill{\footnotesize\input{LALMallocHV}}
00044 \newpage\input{LALMallocC}
00045 \newpage\input{LALMallocTestC}
00046 
00047 </lalLaTeX> */
00048 
00049 
00050 
00051 #ifndef _LALMALLOC_H
00052 #define _LALMALLOC_H
00053 
00054 #include <stddef.h>
00055 #include <lal/LALRCSID.h>
00056 #include <lal/LALConfig.h>
00057 
00058 #ifdef  __cplusplus
00059 extern "C" {
00060 #endif
00061 
00062 
00063 NRCSID( LALMALLOCH, "$Id: LALMalloc.h,v 1.4 2007/06/08 14:41:52 bema Exp $" );
00064 
00065 void *XLALMalloc( size_t n );
00066 void *XLALMallocLong( size_t n, const char *file, int line );
00067 void *XLALCalloc( size_t m, size_t n );
00068 void *XLALCallocLong( size_t m, size_t n, const char *file, int line );
00069 void *XLALRealloc( void *p, size_t n );
00070 void *XLALReallocLong( void *p, size_t n, const char *file, int line );
00071 void  XLALFree( void *p );
00072 #define XLALMalloc( n )        XLALMallocLong( n, __FILE__, __LINE__ )
00073 #define XLALCalloc( m, n )     XLALCallocLong( m, n, __FILE__, __LINE__ )
00074 #define XLALRealloc( p, n )    XLALReallocLong( p, n, __FILE__, __LINE__ )
00075 
00076 #if defined NDEBUG || defined LAL_NDEBUG
00077 
00078 #define LALMalloc                          malloc     
00079 #define LALMallocShort                     malloc     
00080 #define LALMallocLong( n, file, line )     malloc( n )
00081 #define LALCalloc                          calloc        
00082 #define LALCallocShort                     calloc        
00083 #define LALCallocLong( m, n, file, line )  calloc( m, n )
00084 #define LALRealloc                         realloc
00085 #define LALReallocShort                    realloc
00086 #define LALReallocLong( p, n, file, line ) realloc( p, n )
00087 #define LALFree                            free      
00088 #define LALCheckMemoryLeaks()
00089 
00090 #else
00091 
00092 #define LALMalloc( n )        LALMallocLong( n, __FILE__, __LINE__ )
00093 #define LALCalloc( m, n )     LALCallocLong( m, n, __FILE__, __LINE__ )
00094 #define LALRealloc( p, n )    LALReallocLong( p, n, __FILE__, __LINE__ )
00095 
00096 /* global variables to assist in memory debugging */
00097 /* watch the value of these variables to find a particular alloc/free */
00098 extern char  *lalMemDbgArgPtr;   /* set to ptr arg in free or realloc */
00099 extern char  *lalMemDbgRetPtr;   /* set to ptr returned in alloc functions */
00100 extern char  *lalMemDbgPtr;      /* set in both cases */
00101 extern char  *lalMemDbgUsrPtr;   /* avaliable global memory pointer for user */
00102 extern void **lalMemDbgUsrHndl;  /* avaliable global memory handle for user */
00103 extern int    lalIsMemDbgArgPtr; /* ( lalMemDbgUsrPtr == lalMemDbgArgPtr ) */
00104 extern int    lalIsMemDbgRetPtr; /* ( lalMemDbgUsrPtr == lalMemDbgRetPtr ) */
00105 extern int    lalIsMemDbgPtr;    /* ( lalMemDbgUsrPtr == lalMemDbgPtr ) */
00106 
00107 
00108 void *
00109 LALMallocShort( size_t n );
00110 
00111 void *
00112 LALMallocLong( size_t n, const char *file, int line );
00113 
00114 void
00115 LALFree( void *p );
00116 
00117 void *
00118 LALCallocShort( size_t m, size_t n );
00119 
00120 void *
00121 LALCallocLong( size_t m, size_t n, const char *file, int line );
00122 
00123 void *
00124 LALReallocShort( void *p, size_t n );
00125 
00126 void *
00127 LALReallocLong( void *p, size_t n, const char *file, int line );
00128 
00129 void
00130 LALCheckMemoryLeaks( void );
00131 
00132 #endif /* NDEBUG || LAL_NDEBUG */
00133 
00134 #ifdef  __cplusplus
00135 }
00136 #endif
00137 
00138 #endif /* _LALMALLOC_H */

Generated on Mon Oct 13 02:31:51 2008 for LAL by  doxygen 1.5.2