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
00016
00017
00018
00019
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
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
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
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095 #endif