44 #define malloc AV_JOIN(MALLOC_PREFIX, malloc)
45 #define memalign AV_JOIN(MALLOC_PREFIX, memalign)
46 #define posix_memalign AV_JOIN(MALLOC_PREFIX, posix_memalign)
47 #define realloc AV_JOIN(MALLOC_PREFIX, realloc)
48 #define free AV_JOIN(MALLOC_PREFIX, free)
50 void *malloc(
size_t size);
51 void *memalign(
size_t align,
size_t size);
52 int posix_memalign(
void **ptr,
size_t align,
size_t size);
53 void *realloc(
void *ptr,
size_t size);
65 #if CONFIG_MEMALIGN_HACK
70 if (size > (INT_MAX - 32) || !size)
73 #if CONFIG_MEMALIGN_HACK
74 ptr = malloc(size + 32);
77 diff = ((-(long)ptr - 1) & 31) + 1;
78 ptr = (
char *)ptr + diff;
79 ((
char *)ptr)[-1] = diff;
80 #elif HAVE_POSIX_MEMALIGN
81 if (posix_memalign(&ptr, 32, size))
83 #elif HAVE_ALIGNED_MALLOC
84 ptr = _aligned_malloc(size, 32);
86 ptr = memalign(32, size);
119 #if CONFIG_MEMALIGN_HACK
124 if (size > (INT_MAX - 16))
127 #if CONFIG_MEMALIGN_HACK
131 diff = ((
char *)ptr)[-1];
132 return (
char *)realloc((
char *)ptr - diff, size + diff) + diff;
133 #elif HAVE_ALIGNED_MALLOC
134 return _aligned_realloc(ptr, size, 32);
136 return realloc(ptr, size);
162 if (!size || nmemb >= INT_MAX / size)
171 if (!size || nmemb >= INT_MAX / size)
188 #if CONFIG_MEMALIGN_HACK
190 free((
char *)ptr - ((
char *)ptr)[-1]);
191 #elif HAVE_ALIGNED_MALLOC
200 void **ptr = (
void **)arg;
209 memset(ptr, 0, size);
217 int len = strlen(s) + 1;
227 char *ret =
NULL, *end;
232 end = memchr(s, 0, len);
267 uint32_t
a = v << 8 | v >> 16;
268 uint32_t
b = v << 16 | v >> 8;
269 uint32_t c = v << 24 | v;
272 uint32_t a = v | v << 24;
273 uint32_t b = v >> 8 | v << 16;
274 uint32_t c = v >> 16 | v << 8;
321 const uint8_t *src = &dst[-back];
326 memset(dst, *src, cnt);
327 }
else if (back == 2) {
329 }
else if (back == 3) {
331 }
else if (back == 4) {
336 while (cnt > blocklen) {
337 memcpy(dst, src, blocklen);
342 memcpy(dst, src, cnt);
371 if (min_size < *size)
374 min_size =
FFMAX(17 * min_size / 16 + 32, min_size);
391 if (min_size < *size)
393 min_size =
FFMAX(17 * min_size / 16 + 32, min_size);
void * av_malloc(size_t size)
Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if ...
memory handling functions
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 ...
static void fill32(uint8_t *dst, int len)
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.
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.
char * av_strdup(const char *s)
Duplicate the string s.
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)
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 ...