32 #ifndef __OPJ_MALLOC_H
33 #define __OPJ_MALLOC_H
58 #define opj_malloc(size) ((size_t)(size) >= (size_t)-0x100 ? NULL : malloc(size))
60 #define opj_malloc(size) malloc(size)
75 #define opj_calloc(num, size) ((size_t)(num) != 0 && (size_t)(num) >= (size_t)-0x100 / (size_t)(size) ? NULL : calloc(num, size))
77 #define opj_calloc(num, size) calloc(num, size)
90 #include <mm_malloc.h>
91 #define HAVE_MM_MALLOC
95 #define HAVE_MM_MALLOC
100 #define HAVE_MEMALIGN
101 #elif defined(__FreeBSD__)
102 #define HAVE_POSIX_MEMALIGN
104 #elif !defined(__amd64__) && !defined(__APPLE__) && !defined(_AIX)
105 #define HAVE_MEMALIGN
110 #define opj_aligned_malloc(size) malloc(size)
111 #define opj_aligned_free(m) free(m)
113 #ifdef HAVE_MM_MALLOC
114 #undef opj_aligned_malloc
115 #define opj_aligned_malloc(size) _mm_malloc(size, 16)
116 #undef opj_aligned_free
117 #define opj_aligned_free(m) _mm_free(m)
121 extern void*
memalign(
size_t,
size_t);
122 #undef opj_aligned_malloc
123 #define opj_aligned_malloc(size) memalign(16, (size))
124 #undef opj_aligned_free
125 #define opj_aligned_free(m) free(m)
128 #ifdef HAVE_POSIX_MEMALIGN
129 #undef opj_aligned_malloc
130 extern int posix_memalign(
void**,
size_t,
size_t);
134 posix_memalign(&mem, 16, size);
137 #undef opj_aligned_free
138 #define opj_aligned_free(m) free(m)
141 #ifdef ALLOC_PERF_OPT
142 #undef opj_aligned_malloc
143 #define opj_aligned_malloc(size) opj_malloc(size)
144 #undef opj_aligned_free
145 #define opj_aligned_free(m) opj_free(m)
154 #ifdef ALLOC_PERF_OPT
159 #define opj_realloc(m, s) ((size_t)(s) >= (size_t)-0x100 ? NULL : realloc(m, s))
161 #define opj_realloc(m, s) realloc(m, s)
169 #ifdef ALLOC_PERF_OPT
172 #define opj_free(m) free(m)
176 #pragma GCC poison malloc calloc realloc free
void * memalign(size_t, size_t)
#define opj_calloc(num, size)
Allocate a memory block with elements initialized to 0.
Definition: opj_malloc.h:77
#define opj_realloc(m, s)
Reallocate memory blocks.
Definition: opj_malloc.h:161
#define INLINE
Definition: openjpeg.h:65
#define opj_aligned_malloc(size)
Definition: opj_malloc.h:123
#define __attribute__(x)
Definition: opj_includes.h:107
#define OPJ_CALLCONV
Definition: openjpeg.h:92
#define opj_malloc(size)
Allocate an uninitialized memory block.
Definition: opj_malloc.h:60
#define opj_free(m)
Deallocates or frees a memory block.
Definition: opj_malloc.h:172