41 static int fftw_malloc_cnt = 0;
52 static int fftw_malloc_total = 0, fftw_malloc_max = 0, fftw_malloc_cnt_max = 0;
54 #define MAGIC 0xABadCafe 56 #define TWOINTS (2 * sizeof(int)) 58 #define VERBOSE_ALLOCATION 0 60 #if VERBOSE_ALLOCATION 61 #define WHEN_VERBOSE(a) a 63 #define WHEN_VERBOSE(a) 71 fftw_malloc_total += n;
73 if (fftw_malloc_total > fftw_malloc_max)
74 fftw_malloc_max = fftw_malloc_total;
76 p = (
char *) malloc(PAD_FACTOR * n + TWOINTS);
78 fftw_die(
"fftw_malloc: out of memory\n");
82 ((
int *) p)[1] = MAGIC;
83 for (i = 0; i < PAD_FACTOR * n; ++i)
84 p[i + TWOINTS] = (
char) (i ^ 0xDEADBEEF);
88 if (fftw_malloc_cnt > fftw_malloc_cnt_max)
89 fftw_malloc_cnt_max = fftw_malloc_cnt;
92 return (
void *) (p + TWOINTS);
102 q = ((
char *) p) - TWOINTS;
104 fftw_die(
"fftw_free: tried to free NULL+TWOINTS pointer!\n");
107 int n = ((
int *) q)[0];
108 int magic = ((
int *) q)[1];
112 printf(
"FFTW_FREE %d\n", n);
119 fftw_die(
"Wrong magic in fftw_free()!\n");
120 ((
int *) q)[1] = ~MAGIC;
123 fftw_die(
"Tried to free block with corrupt size descriptor!\n");
125 fftw_malloc_total -= n;
127 if (fftw_malloc_total < 0)
128 fftw_die(
"fftw_malloc_total went negative!\n");
131 for (i = n; i < PAD_FACTOR * n; ++i)
132 if (q[i + TWOINTS] != (
char) (i ^ 0xDEADBEEF)) {
134 fprintf(stderr,
"Byte %d past end of array has changed!\n",
136 fftw_die(
"Array bounds overwritten!\n");
138 for (i = 0; i < PAD_FACTOR * n; ++i)
139 q[i + TWOINTS] = (
char) (i ^ 0xBEEFDEAD);
143 if (fftw_malloc_cnt < 0)
144 fftw_die(
"fftw_malloc_cnt went negative!\n");
146 if (fftw_malloc_cnt == 0 && fftw_malloc_total > 0 ||
147 fftw_malloc_cnt > 0 && fftw_malloc_total == 0)
148 fftw_die(
"fftw_malloc_cnt/total not zero at the same time!\n");
173 fftw_die(
"fftw_malloc: out of memory\n");
198 fprintf(stderr,
"fftw: %s", s);
208 if (fftw_malloc_cnt || fftw_malloc_total ||
209 fftw_node_cnt || fftw_plan_cnt || fftw_twiddle_size) {
214 " node=%d plan=%d twiddle=%d\n" 215 "fftw_malloc_total = %d\n",
217 fftw_node_cnt, fftw_plan_cnt, fftw_twiddle_size,
222 if (fftw_node_cnt || fftw_plan_cnt || fftw_twiddle_size) {
226 " node=%d plan=%d twiddle=%d\n",
227 fftw_node_cnt, fftw_plan_cnt, fftw_twiddle_size);
236 printf(
"\nMaximum number of blocks allocated = %d\n" 237 "Maximum number of bytes allocated = %0.3f kB\n",
238 fftw_malloc_cnt_max, fftw_malloc_max / 1024.0);
fftw_die_type_function fftw_die_hook
void fftw_die(const char *s)
void * fftw_malloc(size_t n)
fftw_free_type_function fftw_free_hook
void *(* fftw_malloc_type_function)(size_t n)
void(* fftw_die_type_function)(const char *errString)
void fftw_check_memory_leaks(void)
void(* fftw_free_type_function)(void *p)
fftw_malloc_type_function fftw_malloc_hook
void fftw_print_max_memory_usage(void)