27 #define _XOPEN_SOURCE 600
48 #define malloc AV_JOIN(MALLOC_PREFIX, malloc)
49 #define memalign AV_JOIN(MALLOC_PREFIX, memalign)
50 #define posix_memalign AV_JOIN(MALLOC_PREFIX, posix_memalign)
51 #define realloc AV_JOIN(MALLOC_PREFIX, realloc)
52 #define free AV_JOIN(MALLOC_PREFIX, free)
54 void *malloc(
size_t size);
55 void *memalign(
size_t align,
size_t size);
56 int posix_memalign(
void **ptr,
size_t align,
size_t size);
57 void *realloc(
void *ptr,
size_t size);
62 #define ALIGN (HAVE_AVX ? 32 : 16)
78 #if CONFIG_MEMALIGN_HACK
86 #if CONFIG_MEMALIGN_HACK
87 ptr = malloc(size +
ALIGN);
90 diff = ((~(long)ptr)&(
ALIGN - 1)) + 1;
91 ptr = (
char *)ptr + diff;
92 ((
char *)ptr)[-1] =
diff;
93 #elif HAVE_POSIX_MEMALIGN
95 if (posix_memalign(&ptr,
ALIGN, size))
97 #elif HAVE_ALIGNED_MALLOC
98 ptr = _aligned_malloc(size,
ALIGN);
101 ptr = memalign(
ALIGN, size);
103 ptr = memalign(size,
ALIGN);
136 #if CONFIG_MEMORY_POISONING
145 #if CONFIG_MEMALIGN_HACK
153 #if CONFIG_MEMALIGN_HACK
157 diff = ((
char *)ptr)[-1];
159 ptr = realloc((
char *)ptr - diff, size + diff);
161 ptr = (
char *)ptr + diff;
163 #elif HAVE_ALIGNED_MALLOC
164 return _aligned_realloc(ptr, size + !size,
ALIGN);
166 return realloc(ptr, size + !size);
194 memcpy(&val, ptr,
sizeof(val));
202 memcpy(ptr, &val,
sizeof(val));
208 if (!size || nmemb >= INT_MAX / size)
217 memcpy(&val, ptr,
sizeof(val));
219 memcpy(ptr, &val,
sizeof(val));
220 if (!val && nmemb && size)
228 #if CONFIG_MEMALIGN_HACK
230 int v= ((
char *)ptr)[-1];
232 free((
char *)ptr - v);
234 #elif HAVE_ALIGNED_MALLOC
245 memcpy(&val, arg,
sizeof(val));
246 memcpy(arg, &(
void *){
NULL },
sizeof(
val));
254 memset(ptr, 0, size);
269 size_t len = strlen(s) + 1;
284 end = memchr(s, 0, len);
303 memcpy(ptr, p, size);
311 memcpy(&tab, tab_ptr,
sizeof(tab));
315 memcpy(tab_ptr, &tab,
sizeof(tab));
325 memcpy(&tab, tab_ptr,
sizeof(tab));
329 memcpy(tab_ptr, &tab,
sizeof(tab));
342 tab_elem_data = (
uint8_t *)*tab_ptr + (*nb_ptr) * elem_size;
344 memcpy(tab_elem_data, elem_data, elem_size);
345 else if (CONFIG_MEMORY_POISONING)
351 return tab_elem_data;
376 uint32_t
a = v << 8 | v >> 16;
377 uint32_t
b = v << 16 | v >> 8;
378 uint32_t
c = v << 24 |
v;
381 uint32_t a = v | v << 24;
382 uint32_t b = v >> 8 | v << 16;
383 uint32_t c = v >> 16 | v << 8;
435 memset(dst, *src, cnt);
436 }
else if (back == 2) {
438 }
else if (back == 3) {
440 }
else if (back == 4) {
445 while (cnt > blocklen) {
446 memcpy(dst, src, blocklen);
451 memcpy(dst, src, cnt);
480 if (min_size < *size)
483 min_size =
FFMAX(17 * min_size / 16 + 32, min_size);
501 if (min_size < *size)
503 min_size =
FFMAX(17 * min_size / 16 + 32, min_size);
506 memcpy(ptr, &val,
sizeof(val));
void * av_malloc(size_t size)
Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if ...
const char const char void * val
void * av_realloc_f(void *ptr, size_t nelem, size_t elsize)
Allocate or reallocate a block of memory.
memory handling functions
void * av_dynarray2_add(void **tab_ptr, int *nb_ptr, size_t elem_size, const uint8_t *elem_data)
Add an element of size elem_size to a dynamic array.
void av_max_alloc(size_t max)
Set the maximum size that may me allocated in one block.
static void fill16(uint8_t *dst, int len)
void av_freep(void *arg)
Free a memory block which has been allocated with av_malloc(z)() or av_realloc() and set the pointer ...
#define av_assert0(cond)
assert() equivalent, that is always enabled.
static av_cold int end(AVCodecContext *avctx)
static void fill32(uint8_t *dst, int len)
int av_dynarray_add_nofree(void *tab_ptr, int *nb_ptr, void *elem)
Add an element to a dynamic array.
int av_reallocp(void *ptr, size_t size)
Allocate or reallocate a block of memory.
char * av_strndup(const char *s, size_t len)
Duplicate a substring of the string s.
static int ff_fast_malloc(void *ptr, unsigned int *size, size_t min_size, int zero_realloc)
int av_reallocp_array(void *ptr, size_t nmemb, size_t size)
void av_free(void *ptr)
Free a memory block which has been allocated with av_malloc(z)() or av_realloc(). ...
void * av_fast_realloc(void *ptr, unsigned int *size, size_t min_size)
Reallocate the given block if it is not large enough, otherwise do nothing.
simple assert() macros that are a bit more flexible than ISO C assert().
uint64_t_TMPL AV_WL64 unsigned int_TMPL AV_WL32 unsigned int_TMPL AV_RL24
void av_dynarray_add(void *tab_ptr, int *nb_ptr, void *elem)
Add an element to a dynamic array.
static int av_size_mult(size_t a, size_t b, size_t *r)
Multiply two size_t values checking for overflow.
void * av_memdup(const void *p, size_t size)
Duplicate the buffer p.
const AVS_VideoInfo int align
uint64_t_TMPL AV_WL64 unsigned int_TMPL AV_WL32 unsigned int_TMPL AV_WL24 unsigned int_TMPL AV_WL16 uint64_t_TMPL AV_WB64 unsigned int_TMPL AV_WB32 unsigned int_TMPL AV_RB24
char * av_strdup(const char *s)
Duplicate the string s.
static size_t max_alloc_size
void * av_calloc(size_t nmemb, size_t size)
Allocate a block of nmemb * size bytes with alignment suitable for all memory accesses (including vec...
#define AV_DYNARRAY_ADD(av_size_max, av_elt_size, av_array, av_size, av_success, av_failure)
Add an element of to a dynamic array.
static void fill24(uint8_t *dst, int len)
void av_fast_malloc(void *ptr, unsigned int *size, size_t min_size)
Allocate a buffer, reusing the given one if large enough.
common internal and external API header
void * av_realloc(void *ptr, size_t size)
Allocate or reallocate a block of memory.
void * av_realloc_array(void *ptr, size_t nmemb, size_t size)
static av_always_inline int diff(const uint32_t a, const uint32_t b)
static const struct twinvq_data tab
void av_memcpy_backptr(uint8_t *dst, int back, int cnt)
deliberately overlapping memcpy implementation
void * av_mallocz(size_t size)
Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if ...