00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 #ifndef __OPJ_MALLOC_H
00028 #define __OPJ_MALLOC_H
00029
00038
00041
00042
00048 #ifdef ALLOC_PERF_OPT
00049 void * OPJ_CALLCONV opj_malloc(size_t size);
00050 #else
00051 #define opj_malloc(size) malloc(size)
00052 #endif
00053
00060 #ifdef ALLOC_PERF_OPT
00061 void * OPJ_CALLCONV opj_calloc(size_t _NumOfElements, size_t _SizeOfElements);
00062 #else
00063 #define opj_calloc(num, size) calloc(num, size)
00064 #endif
00065
00071
00072 #ifdef _WIN32
00073
00074 #ifdef __GNUC__
00075 #include <mm_malloc.h>
00076 #define HAVE_MM_MALLOC
00077 #else
00078 #include <malloc.h>
00079 #ifdef _mm_malloc
00080 #define HAVE_MM_MALLOC
00081 #endif
00082 #endif
00083 #else
00084 #if defined(__sun)
00085 #define HAVE_MEMALIGN
00086 #elif defined(__FreeBSD__)
00087 #define HAVE_POSIX_MEMALIGN
00088
00089 #elif !defined(__amd64__) && !defined(__APPLE__) && !defined(_AIX)
00090 #define HAVE_MEMALIGN
00091 #include <malloc.h>
00092 #endif
00093 #endif
00094
00095 #define opj_aligned_malloc(size) malloc(size)
00096 #define opj_aligned_free(m) free(m)
00097
00098 #ifdef HAVE_MM_MALLOC
00099 #undef opj_aligned_malloc
00100 #define opj_aligned_malloc(size) _mm_malloc(size, 16)
00101 #undef opj_aligned_free
00102 #define opj_aligned_free(m) _mm_free(m)
00103 #endif
00104
00105 #ifdef HAVE_MEMALIGN
00106 extern void* memalign(size_t, size_t);
00107 #undef opj_aligned_malloc
00108 #define opj_aligned_malloc(size) memalign(16, (size))
00109 #undef opj_aligned_free
00110 #define opj_aligned_free(m) free(m)
00111 #endif
00112
00113 #ifdef HAVE_POSIX_MEMALIGN
00114 #undef opj_aligned_malloc
00115 extern int posix_memalign(void**, size_t, size_t);
00116
00117 static INLINE void* __attribute__ ((malloc)) opj_aligned_malloc(size_t size){
00118 void* mem = NULL;
00119 posix_memalign(&mem, 16, size);
00120 return mem;
00121 }
00122 #undef opj_aligned_free
00123 #define opj_aligned_free(m) free(m)
00124 #endif
00125
00126 #ifdef ALLOC_PERF_OPT
00127 #undef opj_aligned_malloc
00128 #define opj_aligned_malloc(size) opj_malloc(size)
00129 #undef opj_aligned_free
00130 #define opj_aligned_free(m) opj_free(m)
00131 #endif
00132
00139 #ifdef ALLOC_PERF_OPT
00140 void * OPJ_CALLCONV opj_realloc(void * m, size_t s);
00141 #else
00142 #define opj_realloc(m, s) realloc(m, s)
00143 #endif
00144
00149 #ifdef ALLOC_PERF_OPT
00150 void OPJ_CALLCONV opj_free(void * m);
00151 #else
00152 #define opj_free(m) free(m)
00153 #endif
00154
00155 #ifdef __GNUC__
00156 #pragma GCC poison malloc calloc realloc free
00157 #endif
00158
00159
00163
00164 #endif
00165