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 "avutil.h"
41 #include "common.h"
42 #include "dynarray.h"
43 #include "intreadwrite.h"
44 #include "mem.h"
45 
46 #ifdef MALLOC_PREFIX
47 
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)
53 
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);
58 void free(void *ptr);
59 
60 #endif /* MALLOC_PREFIX */
61 
62 #include "mem_internal.h"
63 
64 #define ALIGN (HAVE_AVX512 ? 64 : (HAVE_AVX ? 32 : 16))
65 
66 /* NOTE: if you want to override these functions with your own
67  * implementations (not recommended) you have to link libav* as
68  * dynamic libraries and remove -Wl,-Bsymbolic from the linker flags.
69  * Note that this will cost performance. */
70 
72 
73 void av_max_alloc(size_t max){
74  atomic_store_explicit(&max_alloc_size, max, memory_order_relaxed);
75 }
76 
77 static int size_mult(size_t a, size_t b, size_t *r)
78 {
79  size_t t;
80 
81 #if (!defined(__INTEL_COMPILER) && AV_GCC_VERSION_AT_LEAST(5,1)) || AV_HAS_BUILTIN(__builtin_mul_overflow)
82  if (__builtin_mul_overflow(a, b, &t))
83  return AVERROR(EINVAL);
84 #else
85  t = a * b;
86  /* Hack inspired from glibc: don't try the division if nelem and elsize
87  * are both less than sqrt(SIZE_MAX). */
88  if ((a | b) >= ((size_t)1 << (sizeof(size_t) * 4)) && a && t / a != b)
89  return AVERROR(EINVAL);
90 #endif
91  *r = t;
92  return 0;
93 }
94 
95 void *av_malloc(size_t size)
96 {
97  void *ptr = NULL;
98 
99  if (size > atomic_load_explicit(&max_alloc_size, memory_order_relaxed))
100  return NULL;
101 
102 #if HAVE_POSIX_MEMALIGN
103  if (size) //OS X on SDK 10.6 has a broken posix_memalign implementation
104  if (posix_memalign(&ptr, ALIGN, size))
105  ptr = NULL;
106 #elif HAVE_ALIGNED_MALLOC
107  ptr = _aligned_malloc(size, ALIGN);
108 #elif HAVE_MEMALIGN
109 #ifndef __DJGPP__
110  ptr = memalign(ALIGN, size);
111 #else
112  ptr = memalign(size, ALIGN);
113 #endif
114  /* Why 64?
115  * Indeed, we should align it:
116  * on 4 for 386
117  * on 16 for 486
118  * on 32 for 586, PPro - K6-III
119  * on 64 for K7 (maybe for P3 too).
120  * Because L1 and L2 caches are aligned on those values.
121  * But I don't want to code such logic here!
122  */
123  /* Why 32?
124  * For AVX ASM. SSE / NEON needs only 16.
125  * Why not larger? Because I did not see a difference in benchmarks ...
126  */
127  /* benchmarks with P3
128  * memalign(64) + 1 3071, 3051, 3032
129  * memalign(64) + 2 3051, 3032, 3041
130  * memalign(64) + 4 2911, 2896, 2915
131  * memalign(64) + 8 2545, 2554, 2550
132  * memalign(64) + 16 2543, 2572, 2563
133  * memalign(64) + 32 2546, 2545, 2571
134  * memalign(64) + 64 2570, 2533, 2558
135  *
136  * BTW, malloc seems to do 8-byte alignment by default here.
137  */
138 #else
139  ptr = malloc(size);
140 #endif
141  if(!ptr && !size) {
142  size = 1;
143  ptr= av_malloc(1);
144  }
145 #if CONFIG_MEMORY_POISONING
146  if (ptr)
147  memset(ptr, FF_MEMORY_POISON, size);
148 #endif
149  return ptr;
150 }
151 
152 void *av_realloc(void *ptr, size_t size)
153 {
154  void *ret;
155  if (size > atomic_load_explicit(&max_alloc_size, memory_order_relaxed))
156  return NULL;
157 
158 #if HAVE_ALIGNED_MALLOC
159  ret = _aligned_realloc(ptr, size + !size, ALIGN);
160 #else
161  ret = realloc(ptr, size + !size);
162 #endif
163 #if CONFIG_MEMORY_POISONING
164  if (ret && !ptr)
165  memset(ret, FF_MEMORY_POISON, size);
166 #endif
167  return ret;
168 }
169 
170 void *av_realloc_f(void *ptr, size_t nelem, size_t elsize)
171 {
172  size_t size;
173  void *r;
174 
175  if (size_mult(elsize, nelem, &size)) {
176  av_free(ptr);
177  return NULL;
178  }
179  r = av_realloc(ptr, size);
180  if (!r)
181  av_free(ptr);
182  return r;
183 }
184 
185 int av_reallocp(void *ptr, size_t size)
186 {
187  void *val;
188 
189  if (!size) {
190  av_freep(ptr);
191  return 0;
192  }
193 
194  memcpy(&val, ptr, sizeof(val));
195  val = av_realloc(val, size);
196 
197  if (!val) {
198  av_freep(ptr);
199  return AVERROR(ENOMEM);
200  }
201 
202  memcpy(ptr, &val, sizeof(val));
203  return 0;
204 }
205 
206 void *av_malloc_array(size_t nmemb, size_t size)
207 {
208  size_t result;
209  if (size_mult(nmemb, size, &result) < 0)
210  return NULL;
211  return av_malloc(result);
212 }
213 
214 #if FF_API_AV_MALLOCZ_ARRAY
215 void *av_mallocz_array(size_t nmemb, size_t size)
216 {
217  size_t result;
218  if (size_mult(nmemb, size, &result) < 0)
219  return NULL;
220  return av_mallocz(result);
221 }
222 #endif
223 
224 void *av_realloc_array(void *ptr, size_t nmemb, size_t size)
225 {
226  size_t result;
227  if (size_mult(nmemb, size, &result) < 0)
228  return NULL;
229  return av_realloc(ptr, result);
230 }
231 
232 int av_reallocp_array(void *ptr, size_t nmemb, size_t size)
233 {
234  void *val;
235 
236  memcpy(&val, ptr, sizeof(val));
237  val = av_realloc_f(val, nmemb, size);
238  memcpy(ptr, &val, sizeof(val));
239  if (!val && nmemb && size)
240  return AVERROR(ENOMEM);
241 
242  return 0;
243 }
244 
245 void av_free(void *ptr)
246 {
247 #if HAVE_ALIGNED_MALLOC
248  _aligned_free(ptr);
249 #else
250  free(ptr);
251 #endif
252 }
253 
254 void av_freep(void *arg)
255 {
256  void *val;
257 
258  memcpy(&val, arg, sizeof(val));
259  memcpy(arg, &(void *){ NULL }, sizeof(val));
260  av_free(val);
261 }
262 
263 void *av_mallocz(size_t size)
264 {
265  void *ptr = av_malloc(size);
266  if (ptr)
267  memset(ptr, 0, size);
268  return ptr;
269 }
270 
271 void *av_calloc(size_t nmemb, size_t size)
272 {
273  size_t result;
274  if (size_mult(nmemb, size, &result) < 0)
275  return NULL;
276  return av_mallocz(result);
277 }
278 
279 char *av_strdup(const char *s)
280 {
281  char *ptr = NULL;
282  if (s) {
283  size_t len = strlen(s) + 1;
284  ptr = av_realloc(NULL, len);
285  if (ptr)
286  memcpy(ptr, s, len);
287  }
288  return ptr;
289 }
290 
291 char *av_strndup(const char *s, size_t len)
292 {
293  char *ret = NULL, *end;
294 
295  if (!s)
296  return NULL;
297 
298  end = memchr(s, 0, len);
299  if (end)
300  len = end - s;
301 
302  ret = av_realloc(NULL, len + 1);
303  if (!ret)
304  return NULL;
305 
306  memcpy(ret, s, len);
307  ret[len] = 0;
308  return ret;
309 }
310 
311 void *av_memdup(const void *p, size_t size)
312 {
313  void *ptr = NULL;
314  if (p) {
315  ptr = av_malloc(size);
316  if (ptr)
317  memcpy(ptr, p, size);
318  }
319  return ptr;
320 }
321 
322 int av_dynarray_add_nofree(void *tab_ptr, int *nb_ptr, void *elem)
323 {
324  void **tab;
325  memcpy(&tab, tab_ptr, sizeof(tab));
326 
327  FF_DYNARRAY_ADD(INT_MAX, sizeof(*tab), tab, *nb_ptr, {
328  tab[*nb_ptr] = elem;
329  memcpy(tab_ptr, &tab, sizeof(tab));
330  }, {
331  return AVERROR(ENOMEM);
332  });
333  return 0;
334 }
335 
336 void av_dynarray_add(void *tab_ptr, int *nb_ptr, void *elem)
337 {
338  void **tab;
339  memcpy(&tab, tab_ptr, sizeof(tab));
340 
341  FF_DYNARRAY_ADD(INT_MAX, sizeof(*tab), tab, *nb_ptr, {
342  tab[*nb_ptr] = elem;
343  memcpy(tab_ptr, &tab, sizeof(tab));
344  }, {
345  *nb_ptr = 0;
346  av_freep(tab_ptr);
347  });
348 }
349 
350 void *av_dynarray2_add(void **tab_ptr, int *nb_ptr, size_t elem_size,
351  const uint8_t *elem_data)
352 {
353  uint8_t *tab_elem_data = NULL;
354 
355  FF_DYNARRAY_ADD(INT_MAX, elem_size, *tab_ptr, *nb_ptr, {
356  tab_elem_data = (uint8_t *)*tab_ptr + (*nb_ptr) * elem_size;
357  if (elem_data)
358  memcpy(tab_elem_data, elem_data, elem_size);
359  else if (CONFIG_MEMORY_POISONING)
360  memset(tab_elem_data, FF_MEMORY_POISON, elem_size);
361  }, {
362  av_freep(tab_ptr);
363  *nb_ptr = 0;
364  });
365  return tab_elem_data;
366 }
367 
368 static void fill16(uint8_t *dst, int len)
369 {
370  uint32_t v = AV_RN16(dst - 2);
371 
372  v |= v << 16;
373 
374  while (len >= 4) {
375  AV_WN32(dst, v);
376  dst += 4;
377  len -= 4;
378  }
379 
380  while (len--) {
381  *dst = dst[-2];
382  dst++;
383  }
384 }
385 
386 static void fill24(uint8_t *dst, int len)
387 {
388 #if HAVE_BIGENDIAN
389  uint32_t v = AV_RB24(dst - 3);
390  uint32_t a = v << 8 | v >> 16;
391  uint32_t b = v << 16 | v >> 8;
392  uint32_t c = v << 24 | v;
393 #else
394  uint32_t v = AV_RL24(dst - 3);
395  uint32_t a = v | v << 24;
396  uint32_t b = v >> 8 | v << 16;
397  uint32_t c = v >> 16 | v << 8;
398 #endif
399 
400  while (len >= 12) {
401  AV_WN32(dst, a);
402  AV_WN32(dst + 4, b);
403  AV_WN32(dst + 8, c);
404  dst += 12;
405  len -= 12;
406  }
407 
408  if (len >= 4) {
409  AV_WN32(dst, a);
410  dst += 4;
411  len -= 4;
412  }
413 
414  if (len >= 4) {
415  AV_WN32(dst, b);
416  dst += 4;
417  len -= 4;
418  }
419 
420  while (len--) {
421  *dst = dst[-3];
422  dst++;
423  }
424 }
425 
426 static void fill32(uint8_t *dst, int len)
427 {
428  uint32_t v = AV_RN32(dst - 4);
429 
430 #if HAVE_FAST_64BIT
431  uint64_t v2= v + ((uint64_t)v<<32);
432  while (len >= 32) {
433  AV_WN64(dst , v2);
434  AV_WN64(dst+ 8, v2);
435  AV_WN64(dst+16, v2);
436  AV_WN64(dst+24, v2);
437  dst += 32;
438  len -= 32;
439  }
440 #endif
441 
442  while (len >= 4) {
443  AV_WN32(dst, v);
444  dst += 4;
445  len -= 4;
446  }
447 
448  while (len--) {
449  *dst = dst[-4];
450  dst++;
451  }
452 }
453 
454 void av_memcpy_backptr(uint8_t *dst, int back, int cnt)
455 {
456  const uint8_t *src = &dst[-back];
457  if (!back)
458  return;
459 
460  if (back == 1) {
461  memset(dst, *src, cnt);
462  } else if (back == 2) {
463  fill16(dst, cnt);
464  } else if (back == 3) {
465  fill24(dst, cnt);
466  } else if (back == 4) {
467  fill32(dst, cnt);
468  } else {
469  if (cnt >= 16) {
470  int blocklen = back;
471  while (cnt > blocklen) {
472  memcpy(dst, src, blocklen);
473  dst += blocklen;
474  cnt -= blocklen;
475  blocklen <<= 1;
476  }
477  memcpy(dst, src, cnt);
478  return;
479  }
480  if (cnt >= 8) {
481  AV_COPY32U(dst, src);
482  AV_COPY32U(dst + 4, src + 4);
483  src += 8;
484  dst += 8;
485  cnt -= 8;
486  }
487  if (cnt >= 4) {
488  AV_COPY32U(dst, src);
489  src += 4;
490  dst += 4;
491  cnt -= 4;
492  }
493  if (cnt >= 2) {
494  AV_COPY16U(dst, src);
495  src += 2;
496  dst += 2;
497  cnt -= 2;
498  }
499  if (cnt)
500  *dst = *src;
501  }
502 }
503 
504 void *av_fast_realloc(void *ptr, unsigned int *size, size_t min_size)
505 {
506  size_t max_size;
507 
508  if (min_size <= *size)
509  return ptr;
510 
511  max_size = atomic_load_explicit(&max_alloc_size, memory_order_relaxed);
512 
513  if (min_size > max_size) {
514  *size = 0;
515  return NULL;
516  }
517 
518  min_size = FFMIN(max_size, FFMAX(min_size + min_size / 16 + 32, min_size));
519 
520  ptr = av_realloc(ptr, min_size);
521  /* we could set this to the unmodified min_size but this is safer
522  * if the user lost the ptr and uses NULL now
523  */
524  if (!ptr)
525  min_size = 0;
526 
527  *size = min_size;
528 
529  return ptr;
530 }
531 
532 static inline void fast_malloc(void *ptr, unsigned int *size, size_t min_size, int zero_realloc)
533 {
534  size_t max_size;
535  void *val;
536 
537  memcpy(&val, ptr, sizeof(val));
538  if (min_size <= *size) {
539  av_assert0(val || !min_size);
540  return;
541  }
542 
543  max_size = atomic_load_explicit(&max_alloc_size, memory_order_relaxed);
544 
545  if (min_size > max_size) {
546  av_freep(ptr);
547  *size = 0;
548  return;
549  }
550  min_size = FFMIN(max_size, FFMAX(min_size + min_size / 16 + 32, min_size));
551  av_freep(ptr);
552  val = zero_realloc ? av_mallocz(min_size) : av_malloc(min_size);
553  memcpy(ptr, &val, sizeof(val));
554  if (!val)
555  min_size = 0;
556  *size = min_size;
557  return;
558 }
559 
560 void av_fast_malloc(void *ptr, unsigned int *size, size_t min_size)
561 {
562  fast_malloc(ptr, size, min_size, 0);
563 }
564 
565 void av_fast_mallocz(void *ptr, unsigned int *size, size_t min_size)
566 {
567  fast_malloc(ptr, size, min_size, 1);
568 }
569 
570 int av_size_mult(size_t a, size_t b, size_t *r)
571 {
572  return size_mult(a, b, r);
573 }
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:570
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:350
ATOMIC_VAR_INIT
#define ATOMIC_VAR_INIT(value)
Definition: stdatomic.h:31
b
#define b
Definition: input.c:40
FF_MEMORY_POISON
#define FF_MEMORY_POISON
Definition: internal.h:87
max
#define max(a, b)
Definition: cuda_runtime.h:33
FFMAX
#define FFMAX(a, b)
Definition: macros.h:47
fast_malloc
static void fast_malloc(void *ptr, unsigned int *size, size_t min_size, int zero_realloc)
Definition: mem.c:532
av_memdup
void * av_memdup(const void *p, size_t size)
Duplicate a buffer with av_malloc().
Definition: mem.c:311
av_max_alloc
void av_max_alloc(size_t max)
Set the maximum size that may be allocated in one block.
Definition: mem.c:73
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:170
fill16
static void fill16(uint8_t *dst, int len)
Definition: mem.c:368
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
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:454
av_malloc_array
void * av_malloc_array(size_t nmemb, size_t size)
Definition: mem.c:206
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:504
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:224
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:254
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:64
fill24
static void fill24(uint8_t *dst, int len)
Definition: mem.c:386
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_realloc
void * av_realloc(void *ptr, size_t size)
Allocate, reallocate, or free a block of memory.
Definition: mem.c:152
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:565
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:336
AV_WN32
#define AV_WN32(p, v)
Definition: intreadwrite.h:376
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:185
fill32
static void fill32(uint8_t *dst, int len)
Definition: mem.c:426
AV_RL24
uint64_t_TMPL AV_WL64 unsigned int_TMPL AV_WL32 unsigned int_TMPL AV_RL24
Definition: bytestream.h:93
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:232
av_mallocz_array
void * av_mallocz_array(size_t nmemb, size_t size)
Definition: mem.c:215
common.h
atomic_store_explicit
#define atomic_store_explicit(object, desired, order)
Definition: stdatomic.h:90
FFMIN
#define FFMIN(a, b)
Definition: macros.h:49
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:263
len
int len
Definition: vorbis_enc_data.h:426
av_calloc
void * av_calloc(size_t nmemb, size_t size)
Definition: mem.c:271
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:245
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:95
max_alloc_size
static atomic_size_t max_alloc_size
Definition: mem.c:71
size_mult
static int size_mult(size_t a, size_t b, size_t *r)
Definition: mem.c:77
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:322
av_strdup
char * av_strdup(const char *s)
Duplicate a string.
Definition: mem.c:279
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:560
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:291