LAL 7.7.0.1-678514e
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
27extern "C" {
28#elif 0
29} /* so that editors will match preceding brace */
30#endif
31
32/** \addtogroup LALMalloc_h */ /** @{ */
33extern size_t lalMallocTotal;
34extern size_t lalMallocTotalPeak;
35void *XLALMalloc(size_t n);
36void *XLALMallocLong(size_t n, const char *file, int line);
37void *XLALCalloc(size_t m, size_t n);
38void *XLALCallocLong(size_t m, size_t n, const char *file, int line);
39void *XLALRealloc(void *p, size_t n);
40void *XLALReallocLong(void *p, size_t n, const char *file, int line);
41void XLALFree(void *p);
42void 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
55int XLALIsMemoryAligned(void *ptr);
56void *XLALMallocAlignedLong(size_t size, const char *file, int line);
57void *XLALMallocAligned(size_t size);
58void *XLALCallocAlignedLong(size_t nelem, size_t elsize, const char *file, int line);
59void *XLALCallocAligned(size_t nelem, size_t elsize);
60void *XLALReallocAlignedLong(void *ptr, size_t size, const char *file, int line);
61void *XLALReallocAligned(void *ptr, size_t size);
62void 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 */
102extern char *lalMemDbgArgPtr; /* set to ptr arg in free or realloc */
103extern char *lalMemDbgRetPtr; /* set to ptr returned in alloc functions */
104extern char *lalMemDbgPtr; /* set in both cases */
105extern char *lalMemDbgUsrPtr; /* avaliable global memory pointer for user */
106extern void **lalMemDbgUsrHndl; /* avaliable global memory handle for user */
107extern int lalIsMemDbgArgPtr; /* ( lalMemDbgUsrPtr == lalMemDbgArgPtr ) */
108extern int lalIsMemDbgRetPtr; /* ( lalMemDbgUsrPtr == lalMemDbgRetPtr ) */
109extern int lalIsMemDbgPtr; /* ( lalMemDbgUsrPtr == lalMemDbgPtr ) */
110#endif /* SWIG */
111
112
113/** \addtogroup LALMalloc_h */ /** @{ */
114void *LALMallocShort(size_t n);
115void *LALMallocLong(size_t n, const char *file, int line);
116void *LALCallocShort(size_t m, size_t n);
117void *LALCallocLong(size_t m, size_t n, const char *file, int line);
118void *LALReallocShort(void *p, size_t n);
119void *LALReallocLong(void *p, size_t n, const char *file, int line);
120void LALFreeShort(void *p);
121void LALFreeLong(void *p, const char *file, int line);
122/** @} */
123
124#endif /* LAL_MEMORY_FUNCTIONS_DISABLED */
125
126void (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 * LALReallocShort(void *p, size_t n)
Definition: LALMalloc.c:690
void LALFreeShort(void *p)
Definition: LALMalloc.c:758
#define XLALMalloc(n)
Definition: LALMalloc.h:44
void * XLALMallocLong(size_t n, const char *file, int line)
Definition: LALMalloc.c:77
void * LALCallocLong(size_t m, size_t n, const char *file, int line)
Definition: LALMalloc.c:660
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)
#define XLALCalloc(m, n)
Definition: LALMalloc.h:45
void * LALReallocLong(void *p, size_t n, const char *file, int line)
Definition: LALMalloc.c:697
#define XLALFree(p)
Definition: LALMalloc.h:47
void * XLALReallocLong(void *p, size_t n, const char *file, int line)
Definition: LALMalloc.c:106
void * XLALCallocLong(size_t m, size_t n, const char *file, int line)
Definition: LALMalloc.c:92
size_t lalMallocTotal
current amount of memory allocated by process
Definition: LALMalloc.c:38
void * LALCallocShort(size_t m, size_t n)
Definition: LALMalloc.c:652
void * LALMallocShort(size_t n)
Definition: LALMalloc.c:617
#define XLALRealloc(p, n)
Definition: LALMalloc.h:46
void * LALMallocLong(size_t n, const char *file, int line)
Definition: LALMalloc.c:624
static const INT4 m
Definition: Random.c:80