LAL  7.5.0.1-8083555
LALMalloc.h
Go to the documentation of this file.
1 /*
2 * Copyright (C) 2007 Jolien Creighton, Kipp Cannon, Josh Willis
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with with program; see the file COPYING. If not, write to the
16 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
17 * MA 02110-1301 USA
18 */
19 
20 #ifndef _LALMALLOC_H
21 #define _LALMALLOC_H
22 
23 #include <stddef.h>
24 #include <lal/LALConfig.h>
25 
26 #ifdef __cplusplus
27 extern "C" {
28 #elif 0
29 } /* so that editors will match preceding brace */
30 #endif
31 
32 /** \addtogroup LALMalloc_h */ /** @{ */
33 extern size_t lalMallocTotal;
34 extern size_t lalMallocTotalPeak;
35 void *XLALMalloc(size_t n);
36 void *XLALMallocLong(size_t n, const char *file, int line);
37 void *XLALCalloc(size_t m, size_t n);
38 void *XLALCallocLong(size_t m, size_t n, const char *file, int line);
39 void *XLALRealloc(void *p, size_t n);
40 void *XLALReallocLong(void *p, size_t n, const char *file, int line);
41 void XLALFree(void *p);
42 void XLALFreeLong(void *p, const char *file, const int line);
43 #ifndef SWIG /* exclude from SWIG interface */
44 #define XLALMalloc( n ) XLALMallocLong( n, __FILE__, __LINE__ )
45 #define XLALCalloc( m, n ) XLALCallocLong( m, n, __FILE__, __LINE__ )
46 #define XLALRealloc( p, n ) XLALReallocLong( p, n, __FILE__, __LINE__ )
47 #define XLALFree( p ) XLALFreeLong( p, __FILE__, __LINE__ )
48 #endif /* SWIG */
49 /** @} */
50 
51 /** \addtogroup LALMalloc_h */ /** @{ */
52 /* presently these are only here if needed */
53 #ifdef LAL_FFTW3_MEMALIGN_ENABLED
54 #define LAL_MEM_ALIGNMENT 0x40
55 int XLALIsMemoryAligned(void *ptr);
56 void *XLALMallocAlignedLong(size_t size, const char *file, int line);
57 void *XLALMallocAligned(size_t size);
58 void *XLALCallocAlignedLong(size_t nelem, size_t elsize, const char *file, int line);
59 void *XLALCallocAligned(size_t nelem, size_t elsize);
60 void *XLALReallocAlignedLong(void *ptr, size_t size, const char *file, int line);
61 void *XLALReallocAligned(void *ptr, size_t size);
62 void XLALFreeAligned(void *ptr);
63 #ifndef SWIG /* exclude from SWIG interface */
64 #define LAL_IS_MEMORY_ALIGNED(ptr) (((size_t)(ptr) % LAL_MEM_ALIGNMENT) == 0)
65 #define XLALMallocAligned(size) XLALMallocAlignedLong(size, __FILE__, __LINE__)
66 #define XLALCallocAligned(nelem, elsize) XLALCallocAlignedLong(nelem, elsize, __FILE__, __LINE__)
67 #define XLALReallocAligned(ptr, size) XLALReallocAlignedLong(ptr, size, __FILE__, __LINE__)
68 #endif /* SWIG */
69 #endif /* LAL_FFTW3_MEMALIGN_ENABLED */
70 /** @} */
71 
72 #ifdef LAL_MEMORY_FUNCTIONS_DISABLED
73 
74 #ifndef SWIG /* exclude from SWIG interface */
75 #define LALMalloc malloc
76 #define LALMallocShort malloc
77 #define LALMallocLong( n, file, line ) malloc( n )
78 #define LALCalloc calloc
79 #define LALCallocShort calloc
80 #define LALCallocLong( m, n, file, line ) calloc( m, n )
81 #define LALRealloc realloc
82 #define LALReallocShort realloc
83 #define LALReallocLong( p, n, file, line ) realloc( p, n )
84 #define LALFree free
85 #define LALFreeShort free
86 #define LALFreeLong( p, file, line ) free( p )
87 #define LALCheckMemoryLeaks()
88 #endif /* SWIG */
89 
90 #else /* !LAL_MEMORY_FUNCTIONS_DISABLED */
91 
92 #ifndef SWIG /* exclude from SWIG interface */
93 #define LALMalloc( n ) LALMallocLong( n, __FILE__, __LINE__ )
94 #define LALCalloc( m, n ) LALCallocLong( m, n, __FILE__, __LINE__ )
95 #define LALRealloc( p, n ) LALReallocLong( p, n, __FILE__, __LINE__ )
96 #define LALFree( p ) LALFreeLong( p, __FILE__, __LINE__ )
97 #endif /* SWIG */
98 
99 /* global variables to assist in memory debugging */
100 /* watch the value of these variables to find a particular alloc/free */
101 #ifndef SWIG /* exclude from SWIG interface */
102 extern char *lalMemDbgArgPtr; /* set to ptr arg in free or realloc */
103 extern char *lalMemDbgRetPtr; /* set to ptr returned in alloc functions */
104 extern char *lalMemDbgPtr; /* set in both cases */
105 extern char *lalMemDbgUsrPtr; /* avaliable global memory pointer for user */
106 extern void **lalMemDbgUsrHndl; /* avaliable global memory handle for user */
107 extern int lalIsMemDbgArgPtr; /* ( lalMemDbgUsrPtr == lalMemDbgArgPtr ) */
108 extern int lalIsMemDbgRetPtr; /* ( lalMemDbgUsrPtr == lalMemDbgRetPtr ) */
109 extern int lalIsMemDbgPtr; /* ( lalMemDbgUsrPtr == lalMemDbgPtr ) */
110 #endif /* SWIG */
111 
112 
113 /** \addtogroup LALMalloc_h */ /** @{ */
114 void *LALMallocShort(size_t n);
115 void *LALMallocLong(size_t n, const char *file, int line);
116 void *LALCallocShort(size_t m, size_t n);
117 void *LALCallocLong(size_t m, size_t n, const char *file, int line);
118 void *LALReallocShort(void *p, size_t n);
119 void *LALReallocLong(void *p, size_t n, const char *file, int line);
120 void LALFreeShort(void *p);
121 void LALFreeLong(void *p, const char *file, int line);
122 /** @} */
123 
124 #endif /* LAL_MEMORY_FUNCTIONS_DISABLED */
125 
126 void (LALCheckMemoryLeaks) (void);
127 
128 #if 0
129 { /* so that editors will match succeeding brace */
130 #elif defined(__cplusplus)
131 }
132 #endif
133 #endif /* _LALMALLOC_H */
int lalIsMemDbgRetPtr
Definition: LALMalloc.c:251
char * lalMemDbgRetPtr
Definition: LALMalloc.c:246
char * lalMemDbgArgPtr
Definition: LALMalloc.c:245
int lalIsMemDbgArgPtr
Definition: LALMalloc.c:250
char * lalMemDbgUsrPtr
Definition: LALMalloc.c:248
void() LALCheckMemoryLeaks(void)
Definition: LALMalloc.c:784
void ** lalMemDbgUsrHndl
Definition: LALMalloc.c:249
int lalIsMemDbgPtr
Definition: LALMalloc.c:252
char * lalMemDbgPtr
Definition: LALMalloc.c:247
void LALFreeShort(void *p)
Definition: LALMalloc.c:758
#define XLALMalloc(n)
Definition: LALMalloc.h:44
void LALFreeLong(void *p, const char *file, int line)
Definition: LALMalloc.c:764
size_t lalMallocTotalPeak
peak amount of memory allocated so far
Definition: LALMalloc.c:39
void XLALFreeLong(void *p, const char *file, const int line)
void * XLALCallocLong(size_t m, size_t n, const char *file, int line)
Definition: LALMalloc.c:92
void * LALCallocShort(size_t m, size_t n)
Definition: LALMalloc.c:652
void * XLALReallocLong(void *p, size_t n, const char *file, int line)
Definition: LALMalloc.c:106
#define XLALCalloc(m, n)
Definition: LALMalloc.h:45
void * LALMallocLong(size_t n, const char *file, int line)
Definition: LALMalloc.c:624
void * LALCallocLong(size_t m, size_t n, const char *file, int line)
Definition: LALMalloc.c:660
#define XLALFree(p)
Definition: LALMalloc.h:47
void * LALReallocLong(void *p, size_t n, const char *file, int line)
Definition: LALMalloc.c:697
size_t lalMallocTotal
current amount of memory allocated by process
Definition: LALMalloc.c:38
void * XLALMallocLong(size_t n, const char *file, int line)
Definition: LALMalloc.c:77
void * LALReallocShort(void *p, size_t n)
Definition: LALMalloc.c:690
#define XLALRealloc(p, n)
Definition: LALMalloc.h:46
void * LALMallocShort(size_t n)
Definition: LALMalloc.c:617
static const INT4 m
Definition: Random.c:80