![]() |
|
00001 /* 00002 * Copyright (c) 2002, 2009 Jens Keiner, Stefan Kunis, Daniel Potts 00003 * 00004 * This program is free software; you can redistribute it and/or modify it under 00005 * the terms of the GNU General Public License as published by the Free Software 00006 * Foundation; either version 2 of the License, or (at your option) any later 00007 * version. 00008 * 00009 * This program is distributed in the hope that it will be useful, but WITHOUT 00010 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 00011 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 00012 * details. 00013 * 00014 * You should have received a copy of the GNU General Public License along with 00015 * this program; if not, write to the Free Software Foundation, Inc., 51 00016 * Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 00017 */ 00018 00019 /* $Id: malloc.c 3100 2009-03-12 08:42:48Z keiner $ */ 00020 00021 #include "nfft3.h" 00022 #include <stdio.h> 00023 #include <stdlib.h> 00024 00025 nfft_malloc_type_function nfft_malloc_hook = 0; 00026 nfft_free_type_function nfft_free_hook = 0; 00027 nfft_die_type_function nfft_die_hook = 0; 00028 00029 void *nfft_malloc(size_t n) 00030 { 00031 void *p; 00032 00033 if (nfft_malloc_hook) 00034 return nfft_malloc_hook(n); 00035 00036 if (n == 0) 00037 n = 1; 00038 00039 if (n == 0) 00040 n = 1; 00041 00042 p = fftw_malloc(n); 00043 00044 if (!p) 00045 { 00046 fprintf(stderr,"nfft_malloc: n = %d.\n",n); 00047 nfft_die("nfft_malloc: out of memory\n"); 00048 } 00049 00050 return p; 00051 } 00052 00053 void nfft_free(void *p) 00054 { 00055 if (p) 00056 { 00057 if (nfft_free_hook) 00058 { 00059 nfft_free_hook(p); 00060 return; 00061 } 00062 00063 fftw_free(p); 00064 } 00065 } 00066 00067 void nfft_die(const char *s) 00068 { 00069 if (nfft_die_hook) 00070 nfft_die_hook(s); 00071 00072 fflush(stdout); 00073 fprintf(stderr, "nfft: %s", s); 00074 exit(EXIT_FAILURE); 00075 }