dsdpmem.h

Go to the documentation of this file.
00001 
00002 #if !defined(__DSDP_MEM_H) 
00003 #define __DSDP_MEM_H
00004 
00007 #include <stdio.h>
00008 #include <stdlib.h>
00009 #include <math.h>
00010 #include <string.h>
00011 #include <float.h>
00012 
00013 extern int DSDPMMalloc(const char*, size_t, void**);
00014 extern int DSDPFFree(void**);
00015 /* Define some macros for memory management */
00016 
00017 /*
00018 #define DSDPFree(a)   0;printf("FREE: %s\n",__FUNCT__); free((*a))
00019 #define DSDPMalloc(a,b)  0;printf("Malloc: %s\n",__FUNCT__); if (b){*(b)=malloc((a)); }
00020 */
00021 
00022 #ifdef DSDPMATLAB
00023 
00024 #define DSDPCALLOC1(VAR,TYPE,MERR) { \
00025    *(VAR) = (TYPE*)mxMalloc(sizeof(TYPE)); \
00026    *MERR=0; \
00027    if ( *(VAR)==0){*(MERR)=1;} \
00028    else {memset(*(VAR),0,sizeof(TYPE));} }
00029 
00030 #define DSDPCALLOC2(VAR,TYPE,SIZE,MERR) { \
00031    *MERR=0; \
00032    *VAR=0; \
00033    if (SIZE>0){ \
00034      *(VAR) = (TYPE*)mxMalloc((SIZE)*sizeof(TYPE)); \
00035      if (*(VAR)==0){ *(MERR)=1;} \
00036      else {memset(*(VAR),0,(SIZE)*sizeof(TYPE));} \
00037    } \
00038 }
00039 
00040 #define DSDPFREE(VAR,MERR)   {if (*(VAR)){mxFree(*(VAR));}*(VAR)=0;*(MERR)=0;}
00041 #endif
00042 
00043 /*
00044 #ifndef DSDPCALLOC1
00045 #define DSDPCALLOC1(VAR,TYPE,MERR)  { (*MERR)=DSDPMMalloc(__FUNCT__,sizeof(TYPE),(void**)(VAR));}
00046 #endif
00047 
00048 #ifndef DSDPCALLOC2
00049 #define DSDPCALLOC2(VAR,TYPE,SIZE,MERR)  { (*MERR)=DSDPMMalloc(__FUNCT__,(SIZE)*sizeof(TYPE),(void**)(VAR));}
00050 #endif
00051 
00052 #ifndef DSDPFREE
00053 #define DSDPFREE(a,b)   {*(b)=DSDPFFree((void**)(a));}
00054 #endif
00055 */
00056 
00057 #ifndef DSDPCALLOC1
00058 #define DSDPCALLOC1(VAR,TYPE,MERR) { \
00059    *(VAR) = (TYPE*)calloc(1, sizeof(TYPE)); \
00060    *MERR=0; \
00061    if ( *(VAR)==0){*(MERR)=1;} \
00062    else {    memset(*(VAR),0,sizeof(TYPE)); } \
00063 }
00064 #endif
00065 
00066 #ifndef DSDPCALLOC2
00067 #define DSDPCALLOC2(VAR,TYPE,SIZE,MERR) { \
00068    *MERR=0; \
00069    *VAR=0; \
00070    if (SIZE>0){ \
00071      *(VAR) = (TYPE*)calloc(SIZE, sizeof(TYPE)); \
00072      if (*(VAR)==0){ *(MERR)=1;} \
00073      else { memset(*(VAR),0,(SIZE)*sizeof(TYPE)); } \
00074    } \
00075 }
00076 #endif
00077 
00078 #ifndef DSDPFREE
00079 #define DSDPFREE(VAR,MERR)   {if (*(VAR)){free(*(VAR));}*(VAR)=0;*(MERR)=0;}
00080 #endif
00081 
00082 /*
00083 #ifndef DSDPCALLOC1
00084 #define DSDPCALLOC1(VAR,TYPE,SIZE,MERR) {*(VAR) = new TYPE;*MERR=0;}
00085 #endif
00086 #ifndef DSDPCALLOC2
00087 #define DSDPCALLOC2(VAR,TYPE,SIZE,MERR) {*(VAR) = new TYPE[SIZE];*MERR=0;}
00088 #endif
00089 #ifndef DSDPFREE
00090 #define DSDPFREE(a,b)   {delete(*(a));*(a)=0;*(b)=0;}
00091 #endif
00092 */
00093 
00094 
00095 #endif

Generated on Wed Nov 11 20:41:02 2009 for DSDP by  doxygen 1.6.1