FFmpeg
mem.c
Go to the documentation of this file.
1 /*
2  * default memory allocator for libavutil
3  * Copyright (c) 2002 Fabrice Bellard
4  *
5  * This file is part of FFmpeg.
6  *
7  * FFmpeg is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2.1 of the License, or (at your option) any later version.
11  *
12  * FFmpeg is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with FFmpeg; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20  */
21 
22 /**
23  * @file
24  * default memory allocator for libavutil
25  */
26 
27 #define _XOPEN_SOURCE 600
28 
29 #include "config.h"
30 
31 #include <limits.h>
32 #include <stdint.h>
33 #include <stdlib.h>
34 #include <stdatomic.h>
35 #include <string.h>
36 #if HAVE_MALLOC_H
37 #include <malloc.h>
38 #endif
39 
40 #include "avassert.h"
41 #include "avutil.h"
42 #include "common.h"
43 #include "dynarray.h"
44 #include "intreadwrite.h"
45 #include "mem.h"
46 
47 #ifdef MALLOC_PREFIX
48 
49 #define malloc AV_JOIN(MALLOC_PREFIX, malloc)
50 #define memalign AV_JOIN(MALLOC_PREFIX, memalign)
51 #define posix_memalign AV_JOIN(MALLOC_PREFIX, posix_memalign)
52 #define realloc AV_JOIN(MALLOC_PREFIX, realloc)
53 #define free AV_JOIN(MALLOC_PREFIX, free)
54 
55 void *malloc(size_t size);
56 void *memalign(size_t align, size_t size);
57 int posix_memalign(void **ptr, size_t align, size_t size);
58 void *realloc(void *ptr, size_t size);
59 void free(void *ptr);
60 
61 #endif /* MALLOC_PREFIX */
62 
63 #include "mem_internal.h"
64 
65 #define ALIGN (HAVE_AVX512 ? 64 : (HAVE_AVX ? 32 : 16))
66 
67 /* NOTE: if you want to override these functions with your own
68  * implementations (not recommended) you have to link libav* as
69  * dynamic libraries and remove -Wl,-Bsymbolic from the linker flags.
70  * Note that this will cost performance. */
71 
73 
74 void av_max_alloc(size_t max){
75  atomic_store_explicit(&max_alloc_size, max, memory_order_relaxed);
76 }
77 
78 void *av_malloc(size_t size)
79 {
80  void *ptr = NULL;
81 
82  if (size > atomic_load_explicit(&max_alloc_size, memory_order_relaxed))
83  return NULL;
84 
85 #if HAVE_POSIX_MEMALIGN
86  if (size) //OS X on SDK 10.6 has a broken posix_memalign implementation
87  if (posix_memalign(&ptr, ALIGN, size))
88  ptr = NULL;
89 #elif HAVE_ALIGNED_MALLOC
90  ptr = _aligned_malloc(size, ALIGN);
91 #elif HAVE_MEMALIGN
92 #ifndef __DJGPP__
93  ptr = memalign(ALIGN, size);
94 #else
95  ptr = memalign(size, ALIGN);
96 #endif
97  /* Why 64?
98  * Indeed, we should align it:
99  * on 4 for 386
100  * on 16 for 486
101  * on 32 for 586, PPro - K6-III
102  * on 64 for K7 (maybe for P3 too).
103  * Because L1 and L2 caches are aligned on those values.
104  * But I don't want to code such logic here!
105  */
106  /* Why 32?
107  * For AVX ASM. SSE / NEON needs only 16.
108  * Why not larger? Because I did not see a difference in benchmarks ...
109  */
110  /* benchmarks with P3
111  * memalign(64) + 1 3071, 3051, 3032
112  * memalign(64) + 2 3051, 3032, 3041
113  * memalign(64) + 4 2911, 2896, 2915
114  * memalign(64) + 8 2545, 2554, 2550
115  * memalign(64) + 16 2543, 2572, 2563
116  * memalign(64) + 32 2546, 2545, 2571
117  * memalign(64) + 64 2570, 2533, 2558
118  *
119  * BTW, malloc seems to do 8-byte alignment by default here.
120  */
121 #else
122  ptr = malloc(size);
123 #endif
124  if(!ptr && !size) {
125  size = 1;
126  ptr= av_malloc(1);
127  }
128 #if CONFIG_MEMORY_POISONING
129  if (ptr)
130  memset(ptr, FF_MEMORY_POISON, size);
131 #endif
132  return ptr;
133 }
134 
135 void *av_realloc(void *ptr, size_t size)
136 {
137  void *ret;
138  if (size > atomic_load_explicit(&max_alloc_size, memory_order_relaxed))
139  return NULL;
140 
141 #if HAVE_ALIGNED_MALLOC
142  ret = _aligned_realloc(ptr, size + !size, ALIGN);
143 #else
144  ret = realloc(ptr, size + !size);
145 #endif
146 #if CONFIG_MEMORY_POISONING
147  if (ret && !ptr)
148  memset(ret, FF_MEMORY_POISON, size);
149 #endif
150  return ret;
151 }
152 
153 void *av_realloc_f(void *ptr, size_t nelem, size_t elsize)
154 {
155  size_t size;
156  void *r;
157 
158  if (av_size_mult(elsize, nelem, &size)) {
159  av_free(ptr);
160  return NULL;
161  }
162  r = av_realloc(ptr, size);
163  if (!r)
164  av_free(ptr);
165  return r;
166 }
167 
168 int av_reallocp(void *ptr, size_t size)
169 {
170  void *val;
171 
172  if (!size) {
173  av_freep(ptr);
174  return 0;
175  }
176 
177  memcpy(&val, ptr, sizeof(val));
178  val = av_realloc(val, size);
179 
180  if (!val) {
181  av_freep(ptr);
182  return AVERROR(ENOMEM);
183  }
184 
185  memcpy(ptr, &val, sizeof(val));
186  return 0;
187 }
188 
189 void *av_malloc_array(size_t nmemb, size_t size)
190 {
191  size_t result;
192  if (av_size_mult(nmemb, size, &result) < 0)
193  return NULL;
194  return av_malloc(result);
195 }
196 
197 void *av_mallocz_array(size_t nmemb, size_t size)
198 {
199  size_t result;
200  if (av_size_mult(nmemb, size, &result) < 0)
201  return NULL;
202  return av_mallocz(result);
203 }
204 
205 void *av_realloc_array(void *ptr, size_t nmemb, size_t size)
206 {
207  size_t result;
208  if (av_size_mult(nmemb, size, &result) < 0)
209  return NULL;
210  return av_realloc(ptr, result);
211 }
212 
213 int av_reallocp_array(void *ptr, size_t nmemb, size_t size)
214 {
215  void *val;
216 
217  memcpy(&val, ptr, sizeof(val));
218  val = av_realloc_f(val, nmemb, size);
219  memcpy(ptr, &val, sizeof(val));
220  if (!val && nmemb && size)
221  return AVERROR(ENOMEM);
222 
223  return 0;
224 }
225 
226 void av_free(void *ptr)
227 {
228 #if HAVE_ALIGNED_MALLOC
229  _aligned_free(ptr);
230 #else
231  free(ptr);
232 #endif
233 }
234 
235 void av_freep(void *arg)
236 {
237  void *val;
238 
239  memcpy(&val, arg, sizeof(val));
240  memcpy(arg, &(void *){ NULL }, sizeof(val));
241  av_free(val);
242 }
243 
244 void *av_mallocz(size_t size)
245 {
246  void *ptr = av_malloc(size);
247  if (ptr)
248  memset(ptr, 0, size);
249  return ptr;
250 }
251 
252 void *av_calloc(size_t nmemb, size_t size)
253 {
254  size_t result;
255  if (av_size_mult(nmemb, size, &result) < 0)
256  return NULL;
257  return av_mallocz(result);
258 }
259 
260 char *av_strdup(const char *s)
261 {
262  char *ptr = NULL;
263  if (s) {
264  size_t len = strlen(s) + 1;
265  ptr = av_realloc(NULL, len);
266  if (ptr)
267  memcpy(ptr, s, len);
268  }
269  return ptr;
270 }
271 
272 char *av_strndup(const char *s, size_t len)
273 {
274  char *ret = NULL, *end;
275 
276  if (!s)
277  return NULL;
278 
279  end = memchr(s, 0, len);
280  if (end)
281  len = end - s;
282 
283  ret = av_realloc(NULL, len + 1);
284  if (!ret)
285  return NULL;
286 
287  memcpy(ret, s, len);
288  ret[len] = 0;
289  return ret;
290 }
291 
292 void *av_memdup(const void *p, size_t size)
293 {
294  void *ptr = NULL;
295  if (p) {
296  ptr = av_malloc(size);
297  if (ptr)
298  memcpy(ptr, p, size);
299  }
300  return ptr;
301 }
302 
303 int av_dynarray_add_nofree(void *tab_ptr, int *nb_ptr, void *elem)
304 {
305  void **tab;
306  memcpy(&tab, tab_ptr, sizeof(tab));
307 
308  FF_DYNARRAY_ADD(INT_MAX, sizeof(*tab), tab, *nb_ptr, {
309  tab[*nb_ptr] = elem;
310  memcpy(tab_ptr, &tab, sizeof(tab));
311  }, {
312  return AVERROR(ENOMEM);
313  });
314  return 0;
315 }
316 
317 void av_dynarray_add(void *tab_ptr, int *nb_ptr, void *elem)
318 {
319  void **tab;
320  memcpy(&tab, tab_ptr, sizeof(tab));
321 
322  FF_DYNARRAY_ADD(INT_MAX, sizeof(*tab), tab, *nb_ptr, {
323  tab[*nb_ptr] = elem;
324  memcpy(tab_ptr, &tab, sizeof(tab));
325  }, {
326  *nb_ptr = 0;
327  av_freep(tab_ptr);
328  });
329 }
330 
331 void *av_dynarray2_add(void **tab_ptr, int *nb_ptr, size_t elem_size,
332  const uint8_t *elem_data)
333 {
334  uint8_t *tab_elem_data = NULL;
335 
336  FF_DYNARRAY_ADD(INT_MAX, elem_size, *tab_ptr, *nb_ptr, {
337  tab_elem_data = (uint8_t *)*tab_ptr + (*nb_ptr) * elem_size;
338  if (elem_data)
339  memcpy(tab_elem_data, elem_data, elem_size);
340  else if (CONFIG_MEMORY_POISONING)
341  memset(tab_elem_data, FF_MEMORY_POISON, elem_size);
342  }, {
343  av_freep(tab_ptr);
344  *nb_ptr = 0;
345  });
346  return tab_elem_data;
347 }
348 
349 static void fill16(uint8_t *dst, int len)
350 {
351  uint32_t v = AV_RN16(dst - 2);
352 
353  v |= v << 16;
354 
355  while (len >= 4) {
356  AV_WN32(dst, v);
357  dst += 4;
358  len -= 4;
359  }
360 
361  while (len--) {
362  *dst = dst[-2];
363  dst++;
364  }
365 }
366 
367 static void fill24(uint8_t *dst, int len)
368 {
369 #if HAVE_BIGENDIAN
370  uint32_t v = AV_RB24(dst - 3);
371  uint32_t a = v << 8 | v >> 16;
372  uint32_t b = v << 16 | v >> 8;
373  uint32_t c = v << 24 | v;
374 #else
375  uint32_t v = AV_RL24(dst - 3);
376  uint32_t a = v | v << 24;
377  uint32_t b = v >> 8 | v << 16;
378  uint32_t c = v >> 16 | v << 8;
379 #endif
380 
381  while (len >= 12) {
382  AV_WN32(dst, a);
383  AV_WN32(dst + 4, b);
384  AV_WN32(dst + 8, c);
385  dst += 12;
386  len -= 12;
387  }
388 
389  if (len >= 4) {
390  AV_WN32(dst, a);
391  dst += 4;
392  len -= 4;
393  }
394 
395  if (len >= 4) {
396  AV_WN32(dst, b);
397  dst += 4;
398  len -= 4;
399  }
400 
401  while (len--) {
402  *dst = dst[-3];
403  dst++;
404  }
405 }
406 
407 static void fill32(uint8_t *dst, int len)
408 {
409  uint32_t v = AV_RN32(dst - 4);
410 
411 #if HAVE_FAST_64BIT
412  uint64_t v2= v + ((uint64_t)v<<32);
413  while (len >= 32) {
414  AV_WN64(dst , v2);
415  AV_WN64(dst+ 8, v2);
416  AV_WN64(dst+16, v2);
417  AV_WN64(dst+24, v2);
418  dst += 32;
419  len -= 32;
420  }
421 #endif
422 
423  while (len >= 4) {
424  AV_WN32(dst, v);
425  dst += 4;
426  len -= 4;
427  }
428 
429  while (len--) {
430  *dst = dst[-4];
431  dst++;
432  }
433 }
434 
435 void av_memcpy_backptr(uint8_t *dst, int back, int cnt)
436 {
437  const uint8_t *src = &dst[-back];
438  if (!back)
439  return;
440 
441  if (back == 1) {
442  memset(dst, *src, cnt);
443  } else if (back == 2) {
444  fill16(dst, cnt);
445  } else if (back == 3) {
446  fill24(dst, cnt);
447  } else if (back == 4) {
448  fill32(dst, cnt);
449  } else {
450  if (cnt >= 16) {
451  int blocklen = back;
452  while (cnt > blocklen) {
453  memcpy(dst, src, blocklen);
454  dst += blocklen;
455  cnt -= blocklen;
456  blocklen <<= 1;
457  }
458  memcpy(dst, src, cnt);
459  return;
460  }
461  if (cnt >= 8) {
462  AV_COPY32U(dst, src);
463  AV_COPY32U(dst + 4, src + 4);
464  src += 8;
465  dst += 8;
466  cnt -= 8;
467  }
468  if (cnt >= 4) {
469  AV_COPY32U(dst, src);
470  src += 4;
471  dst += 4;
472  cnt -= 4;
473  }
474  if (cnt >= 2) {
475  AV_COPY16U(dst, src);
476  src += 2;
477  dst += 2;
478  cnt -= 2;
479  }
480  if (cnt)
481  *dst = *src;
482  }
483 }
484 
485 void *av_fast_realloc(void *ptr, unsigned int *size, size_t min_size)
486 {
487  size_t max_size;
488 
489  if (min_size <= *size)
490  return ptr;
491 
492  max_size = atomic_load_explicit(&max_alloc_size, memory_order_relaxed);
493 
494  if (min_size > max_size) {
495  *size = 0;
496  return NULL;
497  }
498 
499  min_size = FFMIN(max_size, FFMAX(min_size + min_size / 16 + 32, min_size));
500 
501  ptr = av_realloc(ptr, min_size);
502  /* we could set this to the unmodified min_size but this is safer
503  * if the user lost the ptr and uses NULL now
504  */
505  if (!ptr)
506  min_size = 0;
507 
508  *size = min_size;
509 
510  return ptr;
511 }
512 
513 static inline void fast_malloc(void *ptr, unsigned int *size, size_t min_size, int zero_realloc)
514 {
515  size_t max_size;
516  void *val;
517 
518  memcpy(&val, ptr, sizeof(val));
519  if (min_size <= *size) {
520  av_assert0(val || !min_size);
521  return;
522  }
523 
524  max_size = atomic_load_explicit(&max_alloc_size, memory_order_relaxed);
525 
526  if (min_size > max_size) {
527  av_freep(ptr);
528  *size = 0;
529  return;
530  }
531  min_size = FFMIN(max_size, FFMAX(min_size + min_size / 16 + 32, min_size));
532  av_freep(ptr);
533  val = zero_realloc ? av_mallocz(min_size) : av_malloc(min_size);
534  memcpy(ptr, &val, sizeof(val));
535  if (!val)
536  min_size = 0;
537  *size = min_size;
538  return;
539 }
540 
541 void av_fast_malloc(void *ptr, unsigned int *size, size_t min_size)
542 {
543  fast_malloc(ptr, size, min_size, 0);
544 }
545 
546 void av_fast_mallocz(void *ptr, unsigned int *size, size_t min_size)
547 {
548  fast_malloc(ptr, size, min_size, 1);
549 }
550 
551 int av_size_mult(size_t a, size_t b, size_t *r)
552 {
553  size_t t;
554 
555 #if (!defined(__INTEL_COMPILER) && AV_GCC_VERSION_AT_LEAST(5,1)) || AV_HAS_BUILTIN(__builtin_mul_overflow)
556  if (__builtin_mul_overflow(a, b, &t))
557  return AVERROR(EINVAL);
558 #else
559  t = a * b;
560  /* Hack inspired from glibc: don't try the division if nelem and elsize
561  * are both less than sqrt(SIZE_MAX). */
562  if ((a | b) >= ((size_t)1 << (sizeof(size_t) * 4)) && a && t / a != b)
563  return AVERROR(EINVAL);
564 #endif
565  *r = t;
566  return 0;
567 }
av_size_mult
int av_size_mult(size_t a, size_t b, size_t *r)
Multiply two size_t values checking for overflow.
Definition: mem.c:551
FF_DYNARRAY_ADD
#define FF_DYNARRAY_ADD(av_size_max, av_elt_size, av_array, av_size, av_success, av_failure)
Add an element to a dynamic array.
Definition: dynarray.h:45
r
const char * r
Definition: vf_curves.c:116
AVERROR
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining all references to the list are updated That means that if a filter requires that its input and output have the same format amongst a supported all it has to do is use a reference to the same list of formats query_formats can leave some formats unset and return AVERROR(EAGAIN) to cause the negotiation mechanism toagain later. That can be used by filters with complex requirements to use the format negotiated on one link to set the formats supported on another. Frame references ownership and permissions
mem_internal.h
AV_RN16
#define AV_RN16(p)
Definition: intreadwrite.h:360
av_dynarray2_add
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.
Definition: mem.c:331
ATOMIC_VAR_INIT
#define ATOMIC_VAR_INIT(value)
Definition: stdatomic.h:31
b
#define b
Definition: input.c:41
FF_MEMORY_POISON
#define FF_MEMORY_POISON
Definition: internal.h:88
av_mallocz_array
void * av_mallocz_array(size_t nmemb, size_t size)
Definition: mem.c:197
max
#define max(a, b)
Definition: cuda_runtime.h:33
fast_malloc
static void fast_malloc(void *ptr, unsigned int *size, size_t min_size, int zero_realloc)
Definition: mem.c:513
av_memdup
void * av_memdup(const void *p, size_t size)
Duplicate a buffer with av_malloc().
Definition: mem.c:292
av_max_alloc
void av_max_alloc(size_t max)
Set the maximum size that may be allocated in one block.
Definition: mem.c:74
av_realloc_f
void * av_realloc_f(void *ptr, size_t nelem, size_t elsize)
Allocate, reallocate, or free a block of memory.
Definition: mem.c:153
fill16
static void fill16(uint8_t *dst, int len)
Definition: mem.c:349
tab
static const struct twinvq_data tab
Definition: twinvq_data.h:10345
val
static double val(void *priv, double ch)
Definition: aeval.c:76
atomic_size_t
intptr_t atomic_size_t
Definition: stdatomic.h:80
avassert.h
AV_COPY32U
#define AV_COPY32U(d, s)
Definition: intreadwrite.h:572
av_memcpy_backptr
void av_memcpy_backptr(uint8_t *dst, int back, int cnt)
Overlapping memcpy() implementation.
Definition: mem.c:435
av_malloc_array
void * av_malloc_array(size_t nmemb, size_t size)
Definition: mem.c:189
av_fast_realloc
void * av_fast_realloc(void *ptr, unsigned int *size, size_t min_size)
Reallocate the given buffer if it is not large enough, otherwise do nothing.
Definition: mem.c:485
intreadwrite.h
s
#define s(width, name)
Definition: cbs_vp9.c:257
av_realloc_array
void * av_realloc_array(void *ptr, size_t nmemb, size_t size)
Definition: mem.c:205
av_freep
void av_freep(void *arg)
Free a memory block which has been allocated with a function of av_malloc() or av_realloc() family,...
Definition: mem.c:235
AV_COPY16U
#define AV_COPY16U(d, s)
Definition: intreadwrite.h:568
av_assert0
#define av_assert0(cond)
assert() equivalent, that is always enabled.
Definition: avassert.h:37
limits.h
arg
const char * arg
Definition: jacosubdec.c:67
ALIGN
#define ALIGN
Definition: mem.c:65
fill24
static void fill24(uint8_t *dst, int len)
Definition: mem.c:367
result
and forward the result(frame or status change) to the corresponding input. If nothing is possible
NULL
#define NULL
Definition: coverity.c:32
AV_RN32
#define AV_RN32(p)
Definition: intreadwrite.h:364
src
#define src
Definition: vp8dsp.c:255
av_fast_mallocz
void av_fast_mallocz(void *ptr, unsigned int *size, size_t min_size)
Allocate and clear a buffer, reusing the given one if large enough.
Definition: mem.c:546
atomic_load_explicit
#define atomic_load_explicit(object, order)
Definition: stdatomic.h:96
c
Undefined Behavior In the C some operations are like signed integer dereferencing freed accessing outside allocated Undefined Behavior must not occur in a C it is not safe even if the output of undefined operations is unused The unsafety may seem nit picking but Optimizing compilers have in fact optimized code on the assumption that no undefined Behavior occurs Optimizing code based on wrong assumptions can and has in some cases lead to effects beyond the output of computations The signed integer overflow problem in speed critical code Code which is highly optimized and works with signed integers sometimes has the problem that often the output of the computation does not c
Definition: undefined.txt:32
av_dynarray_add
void av_dynarray_add(void *tab_ptr, int *nb_ptr, void *elem)
Add the pointer to an element to a dynamic array.
Definition: mem.c:317
AV_WN32
#define AV_WN32(p, v)
Definition: intreadwrite.h:376
FFMAX
#define FFMAX(a, b)
Definition: common.h:103
size
int size
Definition: twinvq_data.h:10344
av_reallocp
int av_reallocp(void *ptr, size_t size)
Allocate, reallocate, or free a block of memory through a pointer to a pointer.
Definition: mem.c:168
fill32
static void fill32(uint8_t *dst, int len)
Definition: mem.c:407
AV_RL24
uint64_t_TMPL AV_WL64 unsigned int_TMPL AV_WL32 unsigned int_TMPL AV_RL24
Definition: bytestream.h:93
FFMIN
#define FFMIN(a, b)
Definition: common.h:105
a
The reader does not expect b to be semantically here and if the code is changed by maybe adding a a division or other the signedness will almost certainly be mistaken To avoid this confusion a new type was SUINT is the C unsigned type but it holds a signed int to use the same example SUINT a
Definition: undefined.txt:41
av_reallocp_array
int av_reallocp_array(void *ptr, size_t nmemb, size_t size)
Allocate, reallocate, or free an array through a pointer to a pointer.
Definition: mem.c:213
av_realloc
void * av_realloc(void *ptr, size_t size)
Allocate, reallocate, or free a block of memory.
Definition: mem.c:135
common.h
atomic_store_explicit
#define atomic_store_explicit(object, desired, order)
Definition: stdatomic.h:90
av_mallocz
void * av_mallocz(size_t size)
Allocate a memory block with alignment suitable for all memory accesses (including vectors if availab...
Definition: mem.c:244
len
int len
Definition: vorbis_enc_data.h:426
av_free
void av_free(void *ptr)
Free a memory block which has been allocated with a function of av_malloc() or av_realloc() family.
Definition: mem.c:226
ret
ret
Definition: filter_design.txt:187
av_malloc
void * av_malloc(size_t size)
Allocate a memory block with alignment suitable for all memory accesses (including vectors if availab...
Definition: mem.c:78
max_alloc_size
static atomic_size_t max_alloc_size
Definition: mem.c:72
dynarray.h
av_dynarray_add_nofree
int av_dynarray_add_nofree(void *tab_ptr, int *nb_ptr, void *elem)
Add an element to a dynamic array.
Definition: mem.c:303
av_calloc
void * av_calloc(size_t nmemb, size_t size)
Non-inlined equivalent of av_mallocz_array().
Definition: mem.c:252
av_strdup
char * av_strdup(const char *s)
Duplicate a string.
Definition: mem.c:260
avutil.h
mem.h
av_fast_malloc
void av_fast_malloc(void *ptr, unsigned int *size, size_t min_size)
Allocate a buffer, reusing the given one if large enough.
Definition: mem.c:541
AV_WN64
#define AV_WN64(p, v)
Definition: intreadwrite.h:380
AV_RB24
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
Definition: bytestream.h:97
av_strndup
char * av_strndup(const char *s, size_t len)
Duplicate a substring of a string.
Definition: mem.c:272