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 #include <stdint.h>
00031
00032 #include "attributes.h"
00033 #include "error.h"
00034 #include "avutil.h"
00035
00042 #if defined(__INTEL_COMPILER) && __INTEL_COMPILER < 1110 || defined(__SUNPRO_C)
00043 #define DECLARE_ALIGNED(n,t,v) t __attribute__ ((aligned (n))) v
00044 #define DECLARE_ASM_CONST(n,t,v) const t __attribute__ ((aligned (n))) v
00045 #elif defined(__TI_COMPILER_VERSION__)
00046 #define DECLARE_ALIGNED(n,t,v) \
00047 AV_PRAGMA(DATA_ALIGN(v,n)) \
00048 t __attribute__((aligned(n))) v
00049 #define DECLARE_ASM_CONST(n,t,v) \
00050 AV_PRAGMA(DATA_ALIGN(v,n)) \
00051 static const t __attribute__((aligned(n))) v
00052 #elif defined(__GNUC__)
00053 #define DECLARE_ALIGNED(n,t,v) t __attribute__ ((aligned (n))) v
00054 #define DECLARE_ASM_CONST(n,t,v) static const t av_used __attribute__ ((aligned (n))) v
00055 #elif defined(_MSC_VER)
00056 #define DECLARE_ALIGNED(n,t,v) __declspec(align(n)) t v
00057 #define DECLARE_ASM_CONST(n,t,v) __declspec(align(n)) static const t v
00058 #else
00059 #define DECLARE_ALIGNED(n,t,v) t v
00060 #define DECLARE_ASM_CONST(n,t,v) static const t v
00061 #endif
00062
00063 #if AV_GCC_VERSION_AT_LEAST(3,1)
00064 #define av_malloc_attrib __attribute__((__malloc__))
00065 #else
00066 #define av_malloc_attrib
00067 #endif
00068
00069 #if AV_GCC_VERSION_AT_LEAST(4,3)
00070 #define av_alloc_size(...) __attribute__((alloc_size(__VA_ARGS__)))
00071 #else
00072 #define av_alloc_size(...)
00073 #endif
00074
00083 void *av_malloc(size_t size) av_malloc_attrib av_alloc_size(1);
00084
00094 av_alloc_size(1, 2) static inline void *av_malloc_array(size_t nmemb, size_t size)
00095 {
00096 if (size <= 0 || nmemb >= INT_MAX / size)
00097 return NULL;
00098 return av_malloc(nmemb * size);
00099 }
00100
00113 void *av_realloc(void *ptr, size_t size) av_alloc_size(2);
00114
00123 void *av_realloc_f(void *ptr, size_t nelem, size_t elsize);
00124
00133 void av_free(void *ptr);
00134
00143 void *av_mallocz(size_t size) av_malloc_attrib av_alloc_size(1);
00144
00155 void *av_calloc(size_t nmemb, size_t size) av_malloc_attrib;
00156
00167 av_alloc_size(1, 2) static inline void *av_mallocz_array(size_t nmemb, size_t size)
00168 {
00169 if (size <= 0 || nmemb >= INT_MAX / size)
00170 return NULL;
00171 return av_mallocz(nmemb * size);
00172 }
00173
00180 char *av_strdup(const char *s) av_malloc_attrib;
00181
00189 void av_freep(void *ptr);
00190
00198 void av_dynarray_add(void *tab_ptr, int *nb_ptr, void *elem);
00199
00204 static inline int av_size_mult(size_t a, size_t b, size_t *r)
00205 {
00206 size_t t = a * b;
00207
00208
00209 if ((a | b) >= ((size_t)1 << (sizeof(size_t) * 4)) && a && t / a != b)
00210 return AVERROR(EINVAL);
00211 *r = t;
00212 return 0;
00213 }
00214
00218 void av_max_alloc(size_t max);
00219
00229 void av_memcpy_backptr(uint8_t *dst, int back, int cnt);
00230
00235 #endif