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 #define opj_malloc(size) malloc(size)
00049
00056 #define opj_calloc(num, size) calloc(num, size)
00057
00063
00064 #ifdef WIN32
00065
00066 #ifdef __GNUC__
00067 #include <mm_malloc.h>
00068 #define HAVE_MM_MALLOC
00069 #else
00070 #include <malloc.h>
00071 #ifdef _mm_malloc
00072 #define HAVE_MM_MALLOC
00073 #endif
00074 #endif
00075 #else
00076 #if defined(__sun)
00077 #define HAVE_MEMALIGN
00078
00079 #elif !defined(__amd64__) && !defined(__APPLE__)
00080
00081 #define HAVE_POSIX_MEMALIGN
00082 #endif
00083 #endif
00084
00085 #define opj_aligned_malloc(size) malloc(size)
00086 #define opj_aligned_free(m) free(m)
00087
00088 #ifdef HAVE_MM_MALLOC
00089 #undef opj_aligned_malloc
00090 #define opj_aligned_malloc(size) _mm_malloc(size, 16)
00091 #undef opj_aligned_free
00092 #define opj_aligned_free(m) _mm_free(m)
00093 #endif
00094
00095 #ifdef HAVE_MEMALIGN
00096 extern void* memalign(size_t, size_t);
00097 #undef opj_aligned_malloc
00098 #define opj_aligned_malloc(size) memalign(16, (size))
00099 #undef opj_aligned_free
00100 #define opj_aligned_free(m) free(m)
00101 #endif
00102
00103 #ifdef HAVE_POSIX_MEMALIGN
00104 #undef opj_aligned_malloc
00105 extern int posix_memalign(void**, size_t, size_t);
00106
00107 static INLINE void* __attribute__ ((malloc)) opj_aligned_malloc(size_t size){
00108 void* mem = NULL;
00109 posix_memalign(&mem, 16, size);
00110 return mem;
00111 }
00112 #undef opj_aligned_free
00113 #define opj_aligned_free(m) free(m)
00114 #endif
00115
00122 #define opj_realloc(m, s) realloc(m, s)
00123
00128 #define opj_free(m) free(m)
00129
00130 #ifdef __GNUC__
00131 #pragma GCC poison malloc calloc realloc free
00132 #endif
00133
00134
00138
00139 #endif
00140