FFmpeg
mem.h
Go to the documentation of this file.
1 /*
2  * copyright (c) 2006 Michael Niedermayer <michaelni@gmx.at>
3  *
4  * This file is part of FFmpeg.
5  *
6  * FFmpeg is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * FFmpeg is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with FFmpeg; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19  */
20 
21 /**
22  * @file
23  * @ingroup lavu_mem
24  * Memory handling functions
25  */
26 
27 #ifndef AVUTIL_MEM_H
28 #define AVUTIL_MEM_H
29 
30 #include <limits.h>
31 #include <stdint.h>
32 
33 #include "attributes.h"
34 #include "avutil.h"
35 #include "version.h"
36 
37 /**
38  * @addtogroup lavu_mem
39  * Utilities for manipulating memory.
40  *
41  * FFmpeg has several applications of memory that are not required of a typical
42  * program. For example, the computing-heavy components like video decoding and
43  * encoding can be sped up significantly through the use of aligned memory.
44  *
45  * However, for each of FFmpeg's applications of memory, there might not be a
46  * recognized or standardized API for that specific use. Memory alignment, for
47  * instance, varies wildly depending on operating systems, architectures, and
48  * compilers. Hence, this component of @ref libavutil is created to make
49  * dealing with memory consistently possible on all platforms.
50  *
51  * @{
52  */
53 
54 /**
55  * @defgroup lavu_mem_attrs Function Attributes
56  * Function attributes applicable to memory handling functions.
57  *
58  * These function attributes can help compilers emit more useful warnings, or
59  * generate better code.
60  * @{
61  */
62 
63 /**
64  * @def av_malloc_attrib
65  * Function attribute denoting a malloc-like function.
66  *
67  * @see <a href="https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html#index-g_t_0040code_007bmalloc_007d-function-attribute-3251">Function attribute `malloc` in GCC's documentation</a>
68  */
69 
70 #if AV_GCC_VERSION_AT_LEAST(3,1)
71  #define av_malloc_attrib __attribute__((__malloc__))
72 #else
73  #define av_malloc_attrib
74 #endif
75 
76 /**
77  * @def av_alloc_size(...)
78  * Function attribute used on a function that allocates memory, whose size is
79  * given by the specified parameter(s).
80  *
81  * @code{.c}
82  * void *av_malloc(size_t size) av_alloc_size(1);
83  * void *av_calloc(size_t nmemb, size_t size) av_alloc_size(1, 2);
84  * @endcode
85  *
86  * @param ... One or two parameter indexes, separated by a comma
87  *
88  * @see <a href="https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html#index-g_t_0040code_007balloc_005fsize_007d-function-attribute-3220">Function attribute `alloc_size` in GCC's documentation</a>
89  */
90 
91 #if AV_GCC_VERSION_AT_LEAST(4,3)
92  #define av_alloc_size(...) __attribute__((alloc_size(__VA_ARGS__)))
93 #else
94  #define av_alloc_size(...)
95 #endif
96 
97 /**
98  * @}
99  */
100 
101 /**
102  * @defgroup lavu_mem_funcs Heap Management
103  * Functions responsible for allocating, freeing, and copying memory.
104  *
105  * All memory allocation functions have a built-in upper limit of `INT_MAX`
106  * bytes. This may be changed with av_max_alloc(), although exercise extreme
107  * caution when doing so.
108  *
109  * @{
110  */
111 
112 /**
113  * Allocate a memory block with alignment suitable for all memory accesses
114  * (including vectors if available on the CPU).
115  *
116  * @param size Size in bytes for the memory block to be allocated
117  * @return Pointer to the allocated block, or `NULL` if the block cannot
118  * be allocated
119  * @see av_mallocz()
120  */
122 
123 /**
124  * Allocate a memory block with alignment suitable for all memory accesses
125  * (including vectors if available on the CPU) and zero all the bytes of the
126  * block.
127  *
128  * @param size Size in bytes for the memory block to be allocated
129  * @return Pointer to the allocated block, or `NULL` if it cannot be allocated
130  * @see av_malloc()
131  */
133 
134 /**
135  * Allocate a memory block for an array with av_malloc().
136  *
137  * The allocated memory will have size `size * nmemb` bytes.
138  *
139  * @param nmemb Number of element
140  * @param size Size of a single element
141  * @return Pointer to the allocated block, or `NULL` if the block cannot
142  * be allocated
143  * @see av_malloc()
144  */
145 av_alloc_size(1, 2) void *av_malloc_array(size_t nmemb, size_t size);
146 
147 /**
148  * Allocate a memory block for an array with av_mallocz().
149  *
150  * The allocated memory will have size `size * nmemb` bytes.
151  *
152  * @param nmemb Number of elements
153  * @param size Size of the single element
154  * @return Pointer to the allocated block, or `NULL` if the block cannot
155  * be allocated
156  *
157  * @see av_mallocz()
158  * @see av_malloc_array()
159  */
160 void *av_calloc(size_t nmemb, size_t size) av_malloc_attrib av_alloc_size(1, 2);
161 
162 /**
163  * Allocate, reallocate, or free a block of memory.
164  *
165  * If `ptr` is `NULL` and `size` > 0, allocate a new block. Otherwise, expand or
166  * shrink that block of memory according to `size`.
167  *
168  * @param ptr Pointer to a memory block already allocated with
169  * av_realloc() or `NULL`
170  * @param size Size in bytes of the memory block to be allocated or
171  * reallocated
172  *
173  * @return Pointer to a newly-reallocated block or `NULL` if the block
174  * cannot be reallocated
175  *
176  * @warning Unlike av_malloc(), the returned pointer is not guaranteed to be
177  * correctly aligned. The returned pointer must be freed after even
178  * if size is zero.
179  * @see av_fast_realloc()
180  * @see av_reallocp()
181  */
182 void *av_realloc(void *ptr, size_t size) av_alloc_size(2);
183 
184 /**
185  * Allocate, reallocate, or free a block of memory through a pointer to a
186  * pointer.
187  *
188  * If `*ptr` is `NULL` and `size` > 0, allocate a new block. If `size` is
189  * zero, free the memory block pointed to by `*ptr`. Otherwise, expand or
190  * shrink that block of memory according to `size`.
191  *
192  * @param[in,out] ptr Pointer to a pointer to a memory block already allocated
193  * with av_realloc(), or a pointer to `NULL`. The pointer
194  * is updated on success, or freed on failure.
195  * @param[in] size Size in bytes for the memory block to be allocated or
196  * reallocated
197  *
198  * @return Zero on success, an AVERROR error code on failure
199  *
200  * @warning Unlike av_malloc(), the allocated memory is not guaranteed to be
201  * correctly aligned.
202  */
204 int av_reallocp(void *ptr, size_t size);
205 
206 /**
207  * Allocate, reallocate, or free a block of memory.
208  *
209  * This function does the same thing as av_realloc(), except:
210  * - It takes two size arguments and allocates `nelem * elsize` bytes,
211  * after checking the result of the multiplication for integer overflow.
212  * - It frees the input block in case of failure, thus avoiding the memory
213  * leak with the classic
214  * @code{.c}
215  * buf = realloc(buf);
216  * if (!buf)
217  * return -1;
218  * @endcode
219  * pattern.
220  */
221 void *av_realloc_f(void *ptr, size_t nelem, size_t elsize);
222 
223 /**
224  * Allocate, reallocate, or free an array.
225  *
226  * If `ptr` is `NULL` and `nmemb` > 0, allocate a new block.
227  *
228  * @param ptr Pointer to a memory block already allocated with
229  * av_realloc() or `NULL`
230  * @param nmemb Number of elements in the array
231  * @param size Size of the single element of the array
232  *
233  * @return Pointer to a newly-reallocated block or NULL if the block
234  * cannot be reallocated
235  *
236  * @warning Unlike av_malloc(), the allocated memory is not guaranteed to be
237  * correctly aligned. The returned pointer must be freed after even if
238  * nmemb is zero.
239  * @see av_reallocp_array()
240  */
241 av_alloc_size(2, 3) void *av_realloc_array(void *ptr, size_t nmemb, size_t size);
242 
243 /**
244  * Allocate, reallocate an array through a pointer to a pointer.
245  *
246  * If `*ptr` is `NULL` and `nmemb` > 0, allocate a new block.
247  *
248  * @param[in,out] ptr Pointer to a pointer to a memory block already
249  * allocated with av_realloc(), or a pointer to `NULL`.
250  * The pointer is updated on success, or freed on failure.
251  * @param[in] nmemb Number of elements
252  * @param[in] size Size of the single element
253  *
254  * @return Zero on success, an AVERROR error code on failure
255  *
256  * @warning Unlike av_malloc(), the allocated memory is not guaranteed to be
257  * correctly aligned. *ptr must be freed after even if nmemb is zero.
258  */
259 int av_reallocp_array(void *ptr, size_t nmemb, size_t size);
260 
261 /**
262  * Reallocate the given buffer if it is not large enough, otherwise do nothing.
263  *
264  * If the given buffer is `NULL`, then a new uninitialized buffer is allocated.
265  *
266  * If the given buffer is not large enough, and reallocation fails, `NULL` is
267  * returned and `*size` is set to 0, but the original buffer is not changed or
268  * freed.
269  *
270  * A typical use pattern follows:
271  *
272  * @code{.c}
273  * uint8_t *buf = ...;
274  * uint8_t *new_buf = av_fast_realloc(buf, &current_size, size_needed);
275  * if (!new_buf) {
276  * // Allocation failed; clean up original buffer
277  * av_freep(&buf);
278  * return AVERROR(ENOMEM);
279  * }
280  * @endcode
281  *
282  * @param[in,out] ptr Already allocated buffer, or `NULL`
283  * @param[in,out] size Pointer to the size of buffer `ptr`. `*size` is
284  * updated to the new allocated size, in particular 0
285  * in case of failure.
286  * @param[in] min_size Desired minimal size of buffer `ptr`
287  * @return `ptr` if the buffer is large enough, a pointer to newly reallocated
288  * buffer if the buffer was not large enough, or `NULL` in case of
289  * error
290  * @see av_realloc()
291  * @see av_fast_malloc()
292  */
293 void *av_fast_realloc(void *ptr, unsigned int *size, size_t min_size);
294 
295 /**
296  * Allocate a buffer, reusing the given one if large enough.
297  *
298  * Contrary to av_fast_realloc(), the current buffer contents might not be
299  * preserved and on error the old buffer is freed, thus no special handling to
300  * avoid memleaks is necessary.
301  *
302  * `*ptr` is allowed to be `NULL`, in which case allocation always happens if
303  * `size_needed` is greater than 0.
304  *
305  * @code{.c}
306  * uint8_t *buf = ...;
307  * av_fast_malloc(&buf, &current_size, size_needed);
308  * if (!buf) {
309  * // Allocation failed; buf already freed
310  * return AVERROR(ENOMEM);
311  * }
312  * @endcode
313  *
314  * @param[in,out] ptr Pointer to pointer to an already allocated buffer.
315  * `*ptr` will be overwritten with pointer to new
316  * buffer on success or `NULL` on failure
317  * @param[in,out] size Pointer to the size of buffer `*ptr`. `*size` is
318  * updated to the new allocated size, in particular 0
319  * in case of failure.
320  * @param[in] min_size Desired minimal size of buffer `*ptr`
321  * @see av_realloc()
322  * @see av_fast_mallocz()
323  */
324 void av_fast_malloc(void *ptr, unsigned int *size, size_t min_size);
325 
326 /**
327  * Allocate and clear a buffer, reusing the given one if large enough.
328  *
329  * Like av_fast_malloc(), but all newly allocated space is initially cleared.
330  * Reused buffer is not cleared.
331  *
332  * `*ptr` is allowed to be `NULL`, in which case allocation always happens if
333  * `size_needed` is greater than 0.
334  *
335  * @param[in,out] ptr Pointer to pointer to an already allocated buffer.
336  * `*ptr` will be overwritten with pointer to new
337  * buffer on success or `NULL` on failure
338  * @param[in,out] size Pointer to the size of buffer `*ptr`. `*size` is
339  * updated to the new allocated size, in particular 0
340  * in case of failure.
341  * @param[in] min_size Desired minimal size of buffer `*ptr`
342  * @see av_fast_malloc()
343  */
344 void av_fast_mallocz(void *ptr, unsigned int *size, size_t min_size);
345 
346 /**
347  * Free a memory block which has been allocated with a function of av_malloc()
348  * or av_realloc() family.
349  *
350  * @param ptr Pointer to the memory block which should be freed.
351  *
352  * @note `ptr = NULL` is explicitly allowed.
353  * @note It is recommended that you use av_freep() instead, to prevent leaving
354  * behind dangling pointers.
355  * @see av_freep()
356  */
357 void av_free(void *ptr);
358 
359 /**
360  * Free a memory block which has been allocated with a function of av_malloc()
361  * or av_realloc() family, and set the pointer pointing to it to `NULL`.
362  *
363  * @code{.c}
364  * uint8_t *buf = av_malloc(16);
365  * av_free(buf);
366  * // buf now contains a dangling pointer to freed memory, and accidental
367  * // dereference of buf will result in a use-after-free, which may be a
368  * // security risk.
369  *
370  * uint8_t *buf = av_malloc(16);
371  * av_freep(&buf);
372  * // buf is now NULL, and accidental dereference will only result in a
373  * // NULL-pointer dereference.
374  * @endcode
375  *
376  * @param ptr Pointer to the pointer to the memory block which should be freed
377  * @note `*ptr = NULL` is safe and leads to no action.
378  * @see av_free()
379  */
380 void av_freep(void *ptr);
381 
382 /**
383  * Duplicate a string.
384  *
385  * @param s String to be duplicated
386  * @return Pointer to a newly-allocated string containing a
387  * copy of `s` or `NULL` if the string cannot be allocated
388  * @see av_strndup()
389  */
390 char *av_strdup(const char *s) av_malloc_attrib;
391 
392 /**
393  * Duplicate a substring of a string.
394  *
395  * @param s String to be duplicated
396  * @param len Maximum length of the resulting string (not counting the
397  * terminating byte)
398  * @return Pointer to a newly-allocated string containing a
399  * substring of `s` or `NULL` if the string cannot be allocated
400  */
401 char *av_strndup(const char *s, size_t len) av_malloc_attrib;
402 
403 /**
404  * Duplicate a buffer with av_malloc().
405  *
406  * @param p Buffer to be duplicated
407  * @param size Size in bytes of the buffer copied
408  * @return Pointer to a newly allocated buffer containing a
409  * copy of `p` or `NULL` if the buffer cannot be allocated
410  */
411 void *av_memdup(const void *p, size_t size);
412 
413 /**
414  * Overlapping memcpy() implementation.
415  *
416  * @param dst Destination buffer
417  * @param back Number of bytes back to start copying (i.e. the initial size of
418  * the overlapping window); must be > 0
419  * @param cnt Number of bytes to copy; must be >= 0
420  *
421  * @note `cnt > back` is valid, this will copy the bytes we just copied,
422  * thus creating a repeating pattern with a period length of `back`.
423  */
424 void av_memcpy_backptr(uint8_t *dst, int back, int cnt);
425 
426 /**
427  * @}
428  */
429 
430 /**
431  * @defgroup lavu_mem_dynarray Dynamic Array
432  *
433  * Utilities to make an array grow when needed.
434  *
435  * Sometimes, the programmer would want to have an array that can grow when
436  * needed. The libavutil dynamic array utilities fill that need.
437  *
438  * libavutil supports two systems of appending elements onto a dynamically
439  * allocated array, the first one storing the pointer to the value in the
440  * array, and the second storing the value directly. In both systems, the
441  * caller is responsible for maintaining a variable containing the length of
442  * the array, as well as freeing of the array after use.
443  *
444  * The first system stores pointers to values in a block of dynamically
445  * allocated memory. Since only pointers are stored, the function does not need
446  * to know the size of the type. Both av_dynarray_add() and
447  * av_dynarray_add_nofree() implement this system.
448  *
449  * @code
450  * type **array = NULL; //< an array of pointers to values
451  * int nb = 0; //< a variable to keep track of the length of the array
452  *
453  * type to_be_added = ...;
454  * type to_be_added2 = ...;
455  *
456  * av_dynarray_add(&array, &nb, &to_be_added);
457  * if (nb == 0)
458  * return AVERROR(ENOMEM);
459  *
460  * av_dynarray_add(&array, &nb, &to_be_added2);
461  * if (nb == 0)
462  * return AVERROR(ENOMEM);
463  *
464  * // Now:
465  * // nb == 2
466  * // &to_be_added == array[0]
467  * // &to_be_added2 == array[1]
468  *
469  * av_freep(&array);
470  * @endcode
471  *
472  * The second system stores the value directly in a block of memory. As a
473  * result, the function has to know the size of the type. av_dynarray2_add()
474  * implements this mechanism.
475  *
476  * @code
477  * type *array = NULL; //< an array of values
478  * int nb = 0; //< a variable to keep track of the length of the array
479  *
480  * type to_be_added = ...;
481  * type to_be_added2 = ...;
482  *
483  * type *addr = av_dynarray2_add((void **)&array, &nb, sizeof(*array), NULL);
484  * if (!addr)
485  * return AVERROR(ENOMEM);
486  * memcpy(addr, &to_be_added, sizeof(to_be_added));
487  *
488  * // Shortcut of the above.
489  * type *addr = av_dynarray2_add((void **)&array, &nb, sizeof(*array),
490  * (const void *)&to_be_added2);
491  * if (!addr)
492  * return AVERROR(ENOMEM);
493  *
494  * // Now:
495  * // nb == 2
496  * // to_be_added == array[0]
497  * // to_be_added2 == array[1]
498  *
499  * av_freep(&array);
500  * @endcode
501  *
502  * @{
503  */
504 
505 /**
506  * Add the pointer to an element to a dynamic array.
507  *
508  * The array to grow is supposed to be an array of pointers to
509  * structures, and the element to add must be a pointer to an already
510  * allocated structure.
511  *
512  * The array is reallocated when its size reaches powers of 2.
513  * Therefore, the amortized cost of adding an element is constant.
514  *
515  * In case of success, the pointer to the array is updated in order to
516  * point to the new grown array, and the number pointed to by `nb_ptr`
517  * is incremented.
518  * In case of failure, the array is freed, `*tab_ptr` is set to `NULL` and
519  * `*nb_ptr` is set to 0.
520  *
521  * @param[in,out] tab_ptr Pointer to the array to grow
522  * @param[in,out] nb_ptr Pointer to the number of elements in the array
523  * @param[in] elem Element to add
524  * @see av_dynarray_add_nofree(), av_dynarray2_add()
525  */
526 void av_dynarray_add(void *tab_ptr, int *nb_ptr, void *elem);
527 
528 /**
529  * Add an element to a dynamic array.
530  *
531  * Function has the same functionality as av_dynarray_add(),
532  * but it doesn't free memory on fails. It returns error code
533  * instead and leave current buffer untouched.
534  *
535  * @return >=0 on success, negative otherwise
536  * @see av_dynarray_add(), av_dynarray2_add()
537  */
539 int av_dynarray_add_nofree(void *tab_ptr, int *nb_ptr, void *elem);
540 
541 /**
542  * Add an element of size `elem_size` to a dynamic array.
543  *
544  * The array is reallocated when its number of elements reaches powers of 2.
545  * Therefore, the amortized cost of adding an element is constant.
546  *
547  * In case of success, the pointer to the array is updated in order to
548  * point to the new grown array, and the number pointed to by `nb_ptr`
549  * is incremented.
550  * In case of failure, the array is freed, `*tab_ptr` is set to `NULL` and
551  * `*nb_ptr` is set to 0.
552  *
553  * @param[in,out] tab_ptr Pointer to the array to grow
554  * @param[in,out] nb_ptr Pointer to the number of elements in the array
555  * @param[in] elem_size Size in bytes of an element in the array
556  * @param[in] elem_data Pointer to the data of the element to add. If
557  * `NULL`, the space of the newly added element is
558  * allocated but left uninitialized.
559  *
560  * @return Pointer to the data of the element to copy in the newly allocated
561  * space
562  * @see av_dynarray_add(), av_dynarray_add_nofree()
563  */
564 void *av_dynarray2_add(void **tab_ptr, int *nb_ptr, size_t elem_size,
565  const uint8_t *elem_data);
566 
567 /**
568  * @}
569  */
570 
571 /**
572  * @defgroup lavu_mem_misc Miscellaneous Functions
573  *
574  * Other functions related to memory allocation.
575  *
576  * @{
577  */
578 
579 /**
580  * Multiply two `size_t` values checking for overflow.
581  *
582  * @param[in] a Operand of multiplication
583  * @param[in] b Operand of multiplication
584  * @param[out] r Pointer to the result of the operation
585  * @return 0 on success, AVERROR(EINVAL) on overflow
586  */
587 int av_size_mult(size_t a, size_t b, size_t *r);
588 
589 /**
590  * Set the maximum size that may be allocated in one block.
591  *
592  * The value specified with this function is effective for all libavutil's @ref
593  * lavu_mem_funcs "heap management functions."
594  *
595  * By default, the max value is defined as `INT_MAX`.
596  *
597  * @param max Value to be set as the new maximum size
598  *
599  * @warning Exercise extreme caution when using this function. Don't touch
600  * this if you do not understand the full consequence of doing so.
601  */
602 void av_max_alloc(size_t max);
603 
604 /**
605  * @}
606  * @}
607  */
608 
609 #endif /* AVUTIL_MEM_H */
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:565
r
const char * r
Definition: vf_curves.c:126
av_malloc_attrib
#define av_malloc_attrib
Definition: mem.h:73
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:341
b
#define b
Definition: input.c:41
max
#define max(a, b)
Definition: cuda_runtime.h:33
av_memdup
void * av_memdup(const void *p, size_t size)
Duplicate a buffer with av_malloc().
Definition: mem.c:302
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:171
av_memcpy_backptr
void av_memcpy_backptr(uint8_t *dst, int back, int cnt)
Overlapping memcpy() implementation.
Definition: mem.c:445
av_malloc_array
void * av_malloc_array(size_t nmemb, size_t size)
Definition: mem.c:207
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:495
s
#define s(width, name)
Definition: cbs_vp9.c:256
av_realloc_array
void * av_realloc_array(void *ptr, size_t nmemb, size_t size)
Definition: mem.c:215
av_freep
void av_freep(void *ptr)
Free a memory block which has been allocated with a function of av_malloc() or av_realloc() family,...
Definition: mem.c:245
limits.h
av_alloc_size
#define av_alloc_size(...)
Definition: mem.h:94
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:560
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:327
size
int size
Definition: twinvq_data.h:10344
av_reallocp
av_warn_unused_result 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:186
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 an array through a pointer to a pointer.
Definition: mem.c:223
attributes.h
av_warn_unused_result
#define av_warn_unused_result
Definition: attributes.h:64
av_mallocz
void * av_mallocz(size_t size) av_malloc_attrib 1(1)
Allocate a memory block with alignment suitable for all memory accesses (including vectors if availab...
Definition: mem.c:254
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:236
version.h
av_malloc
void * av_malloc(size_t size) av_malloc_attrib 1(1)
Allocate a memory block with alignment suitable for all memory accesses (including vectors if availab...
Definition: mem.c:96
av_dynarray_add_nofree
av_warn_unused_result int av_dynarray_add_nofree(void *tab_ptr, int *nb_ptr, void *elem)
Add an element to a dynamic array.
Definition: mem.c:313
av_strdup
char * av_strdup(const char *s) av_malloc_attrib
Duplicate a string.
Definition: mem.c:270
avutil.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:555
av_calloc
void * av_calloc(size_t nmemb, size_t size) av_malloc_attrib 1(1
Allocate a memory block for an array with av_mallocz().
av_strndup
char * av_strndup(const char *s, size_t len) av_malloc_attrib
Duplicate a substring of a string.
Definition: mem.c:282
av_realloc
void void * av_realloc(void *ptr, size_t size) 1(2)
Allocate, reallocate, or free a block of memory.
Definition: mem.c:153