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 "attributes.h"
00030 #include "error.h"
00031 #include "avutil.h"
00032
00039 #if defined(__INTEL_COMPILER) && __INTEL_COMPILER < 1110 || defined(__SUNPRO_C)
00040 #define DECLARE_ALIGNED(n,t,v) t __attribute__ ((aligned (n))) v
00041 #define DECLARE_ASM_CONST(n,t,v) const t __attribute__ ((aligned (n))) v
00042 #elif defined(__TI_COMPILER_VERSION__)
00043 #define DECLARE_ALIGNED(n,t,v) \
00044 AV_PRAGMA(DATA_ALIGN(v,n)) \
00045 t __attribute__((aligned(n))) v
00046 #define DECLARE_ASM_CONST(n,t,v) \
00047 AV_PRAGMA(DATA_ALIGN(v,n)) \
00048 static const t __attribute__((aligned(n))) v
00049 #elif defined(__GNUC__)
00050 #define DECLARE_ALIGNED(n,t,v) t __attribute__ ((aligned (n))) v
00051 #define DECLARE_ASM_CONST(n,t,v) static const t av_used __attribute__ ((aligned (n))) v
00052 #elif defined(_MSC_VER)
00053 #define DECLARE_ALIGNED(n,t,v) __declspec(align(n)) t v
00054 #define DECLARE_ASM_CONST(n,t,v) __declspec(align(n)) static const t v
00055 #else
00056 #define DECLARE_ALIGNED(n,t,v) t v
00057 #define DECLARE_ASM_CONST(n,t,v) static const t v
00058 #endif
00059
00060 #if AV_GCC_VERSION_AT_LEAST(3,1)
00061 #define av_malloc_attrib __attribute__((__malloc__))
00062 #else
00063 #define av_malloc_attrib
00064 #endif
00065
00066 #if AV_GCC_VERSION_AT_LEAST(4,3)
00067 #define av_alloc_size(n) __attribute__((alloc_size(n)))
00068 #else
00069 #define av_alloc_size(n)
00070 #endif
00071
00080 void *av_malloc(size_t size) av_malloc_attrib av_alloc_size(1);
00081
00094 void *av_realloc(void *ptr, size_t size) av_alloc_size(2);
00095
00104 void *av_realloc_f(void *ptr, size_t nelem, size_t elsize);
00105
00114 void av_free(void *ptr);
00115
00124 void *av_mallocz(size_t size) av_malloc_attrib av_alloc_size(1);
00125
00136 void *av_calloc(size_t nmemb, size_t size) av_malloc_attrib;
00137
00144 char *av_strdup(const char *s) av_malloc_attrib;
00145
00153 void av_freep(void *ptr);
00154
00162 void av_dynarray_add(void *tab_ptr, int *nb_ptr, void *elem);
00163
00168 static inline int av_size_mult(size_t a, size_t b, size_t *r)
00169 {
00170 size_t t = a * b;
00171
00172
00173 if ((a | b) >= ((size_t)1 << (sizeof(size_t) * 4)) && a && t / a != b)
00174 return AVERROR(EINVAL);
00175 *r = t;
00176 return 0;
00177 }
00178
00183 #endif