bsp_alloc.h

Go to the documentation of this file.
00001 /*
00002     BSPonMPI. This is an implementation of the BSPlib standard on top of MPI
00003     Copyright (C) 2006  Wijnand J. Suijlen
00004                                                                                 
00005     This library is free software; you can redistribute it and/or
00006     modify it under the terms of the GNU Lesser General Public
00007     License as published by the Free Software Foundation; either
00008     version 2.1 of the License, or (at your option) any later version.
00009                                                                                 
00010     This library is distributed in the hope that it will be useful,
00011     but WITHOUT ANY WARRANTY; without even the implied warranty of
00012     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013     Lesser General Public License for more details.
00014                                                                                 
00015     You should have received a copy of the GNU Lesser General Public
00016     License along with this library; if not, write to the Free Software
00017     Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
00018                                                                                 
00019     You may contact me via electronic mail:
00020       wjsuijle@users.sourceforge.net
00021     or snail mail:
00022       W.J. Suijlen
00023       Kraaiheidelaan 10
00024       2803 VP Gouda
00025       The Netherlands
00026 */
00027 
00032 #ifndef BSP_ALLOC_H
00033 #define BSP_ALLOC_H
00034 
00035 #include <config.h>
00036 #include <stdlib.h>
00037 #include "bsp_abort.h"
00038 
00040 #define bsp_malloc( n, sz) bsp_mallocx((n), (sz), \
00041                           __func__, __FILE__, __LINE__ )
00042 
00044 #define bsp_calloc( n, sz) bsp_callocx((n), (sz), \
00045                           __func__, __FILE__, __LINE__ )
00046 
00057 static inline void *
00058 bsp_mallocx (const size_t n, const size_t sz, 
00059             const char *func, const char *file, int line)
00060 {
00061   void *result;
00062 
00063   if (n * sz == 0)
00064     return NULL;
00065   
00066   result = (void *) malloc (n * sz);
00067   if (result == NULL)
00068     bsp_intern_abort (ERR_NOT_ENOUGH_MEMORY, func, file, line);
00069   
00070   return result;
00071 }
00072 
00082 static inline void *
00083 bsp_callocx (const size_t n, const size_t sz, 
00084              const char *func, const char *file, int line)
00085 {
00086   void *result;
00087 
00088   if (n * sz == 0)
00089     return NULL;
00090     
00091   result = (void *) calloc (n, sz);
00092   if (result == NULL)
00093     bsp_intern_abort (ERR_NOT_ENOUGH_MEMORY, func, file, line);
00094    
00095   return result;
00096 }
00097 
00101 static inline void
00102 bsp_free (void *ptr)
00103 {
00104   if (ptr != NULL)
00105     free (ptr);
00106 }
00107 
00108 #endif

Generated on Sat Apr 8 20:12:29 2006 for BSPonMPI by  doxygen 1.4.6