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
00033 #if defined(__INTEL_COMPILER) && __INTEL_COMPILER < 1110 || defined(__SUNPRO_C)
00034 #define DECLARE_ALIGNED(n,t,v) t __attribute__ ((aligned (n))) v
00035 #define DECLARE_ASM_CONST(n,t,v) const t __attribute__ ((aligned (n))) v
00036 #elif defined(__TI_COMPILER_VERSION__)
00037 #define DECLARE_ALIGNED(n,t,v) \
00038 AV_PRAGMA(DATA_ALIGN(v,n)) \
00039 t __attribute__((aligned(n))) v
00040 #define DECLARE_ASM_CONST(n,t,v) \
00041 AV_PRAGMA(DATA_ALIGN(v,n)) \
00042 static const t __attribute__((aligned(n))) v
00043 #elif defined(__GNUC__)
00044 #define DECLARE_ALIGNED(n,t,v) t __attribute__ ((aligned (n))) v
00045 #define DECLARE_ASM_CONST(n,t,v) static const t av_used __attribute__ ((aligned (n))) v
00046 #elif defined(_MSC_VER)
00047 #define DECLARE_ALIGNED(n,t,v) __declspec(align(n)) t v
00048 #define DECLARE_ASM_CONST(n,t,v) __declspec(align(n)) static const t v
00049 #else
00050 #define DECLARE_ALIGNED(n,t,v) t v
00051 #define DECLARE_ASM_CONST(n,t,v) static const t v
00052 #endif
00053
00054 #if AV_GCC_VERSION_AT_LEAST(3,1)
00055 #define av_malloc_attrib __attribute__((__malloc__))
00056 #else
00057 #define av_malloc_attrib
00058 #endif
00059
00060 #if AV_GCC_VERSION_AT_LEAST(4,3)
00061 #define av_alloc_size(n) __attribute__((alloc_size(n)))
00062 #else
00063 #define av_alloc_size(n)
00064 #endif
00065
00074 void *av_malloc(size_t size) av_malloc_attrib av_alloc_size(1);
00075
00088 void *av_realloc(void *ptr, size_t size) av_alloc_size(2);
00089
00098 void *av_realloc_f(void *ptr, size_t nelem, size_t elsize);
00099
00108 void av_free(void *ptr);
00109
00118 void *av_mallocz(size_t size) av_malloc_attrib av_alloc_size(1);
00119
00130 void *av_calloc(size_t nmemb, size_t size) av_malloc_attrib;
00131
00138 char *av_strdup(const char *s) av_malloc_attrib;
00139
00147 void av_freep(void *ptr);
00148
00156 void av_dynarray_add(void *tab_ptr, int *nb_ptr, void *elem);
00157
00162 static inline int av_size_mult(size_t a, size_t b, size_t *r)
00163 {
00164 size_t t = a * b;
00165
00166
00167 if ((a | b) >= ((size_t)1 << (sizeof(size_t) * 4)) && a && t / a != b)
00168 return AVERROR(EINVAL);
00169 *r = t;
00170 return 0;
00171 }
00172
00173 #endif