00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00026 #ifndef AVUTIL_MEM_H
00027 #define AVUTIL_MEM_H
00028
00029 #include <limits.h>
00030
00031 #include "attributes.h"
00032 #include "error.h"
00033 #include "avutil.h"
00034
00041 #if defined(__INTEL_COMPILER) && __INTEL_COMPILER < 1110 || defined(__SUNPRO_C)
00042 #define DECLARE_ALIGNED(n,t,v) t __attribute__ ((aligned (n))) v
00043 #define DECLARE_ASM_CONST(n,t,v) const t __attribute__ ((aligned (n))) v
00044 #elif defined(__TI_COMPILER_VERSION__)
00045 #define DECLARE_ALIGNED(n,t,v) \
00046 AV_PRAGMA(DATA_ALIGN(v,n)) \
00047 t __attribute__((aligned(n))) v
00048 #define DECLARE_ASM_CONST(n,t,v) \
00049 AV_PRAGMA(DATA_ALIGN(v,n)) \
00050 static const t __attribute__((aligned(n))) v
00051 #elif defined(__GNUC__)
00052 #define DECLARE_ALIGNED(n,t,v) t __attribute__ ((aligned (n))) v
00053 #define DECLARE_ASM_CONST(n,t,v) static const t av_used __attribute__ ((aligned (n))) v
00054 #elif defined(_MSC_VER)
00055 #define DECLARE_ALIGNED(n,t,v) __declspec(align(n)) t v
00056 #define DECLARE_ASM_CONST(n,t,v) __declspec(align(n)) static const t v
00057 #else
00058 #define DECLARE_ALIGNED(n,t,v) t v
00059 #define DECLARE_ASM_CONST(n,t,v) static const t v
00060 #endif
00061
00062 #if AV_GCC_VERSION_AT_LEAST(3,1)
00063 #define av_malloc_attrib __attribute__((__malloc__))
00064 #else
00065 #define av_malloc_attrib
00066 #endif
00067
00068 #if AV_GCC_VERSION_AT_LEAST(4,3)
00069 #define av_alloc_size(...) __attribute__((alloc_size(__VA_ARGS__)))
00070 #else
00071 #define av_alloc_size(...)
00072 #endif
00073
00082 void *av_malloc(size_t size) av_malloc_attrib av_alloc_size(1);
00083
00093 av_alloc_size(1,2) static inline void *av_malloc_array(size_t nmemb, size_t size)
00094 {
00095 if (size <= 0 || nmemb >= INT_MAX / size)
00096 return NULL;
00097 return av_malloc(nmemb * size);
00098 }
00099
00112 void *av_realloc(void *ptr, size_t size) av_alloc_size(2);
00113
00122 void *av_realloc_f(void *ptr, size_t nelem, size_t elsize);
00123
00132 void av_free(void *ptr);
00133
00142 void *av_mallocz(size_t size) av_malloc_attrib av_alloc_size(1);
00143
00154 void *av_calloc(size_t nmemb, size_t size) av_malloc_attrib;
00155
00166 av_alloc_size(1,2) static inline void *av_mallocz_array(size_t nmemb, size_t size)
00167 {
00168 if (size <= 0 || nmemb >= INT_MAX / size)
00169 return NULL;
00170 return av_mallocz(nmemb * size);
00171 }
00172
00179 char *av_strdup(const char *s) av_malloc_attrib;
00180
00188 void av_freep(void *ptr);
00189
00197 void av_dynarray_add(void *tab_ptr, int *nb_ptr, void *elem);
00198
00203 static inline int av_size_mult(size_t a, size_t b, size_t *r)
00204 {
00205 size_t t = a * b;
00206
00207
00208 if ((a | b) >= ((size_t)1 << (sizeof(size_t) * 4)) && a && t / a != b)
00209 return AVERROR(EINVAL);
00210 *r = t;
00211 return 0;
00212 }
00213
00217 void av_max_alloc(size_t max);
00218
00223 #endif