FFmpeg
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
Macros
dynarray.h File Reference
#include "log.h"
#include "mem.h"

Go to the source code of this file.

Macros

#define FF_DYNARRAY_ADD(av_size_max, av_elt_size, av_array, av_size, av_success, av_failure)
 Add an element of to a dynamic array. More...
 

Macro Definition Documentation

#define FF_DYNARRAY_ADD (   av_size_max,
  av_elt_size,
  av_array,
  av_size,
  av_success,
  av_failure 
)
Value:
do { \
size_t av_size_new = (av_size); \
if (!((av_size) & ((av_size) - 1))) { \
av_size_new = (av_size) ? (av_size) << 1 : 1; \
if (av_size_new > (av_size_max) / (av_elt_size)) { \
av_size_new = 0; \
} else { \
void *av_array_new = \
av_realloc((av_array), av_size_new * (av_elt_size)); \
if (!av_array_new) \
av_size_new = 0; \
(av_array) = av_array_new; \
} \
} \
if (av_size_new) { \
{ av_success } \
(av_size)++; \
} else { \
av_failure \
} \
} while (0)
void * av_realloc(void *ptr, size_t size)
Allocate, reallocate, or free a block of memory.
Definition: mem.c:135
typedef void(APIENTRY *FF_PFNGLACTIVETEXTUREPROC)(GLenum texture)
if(ret< 0)
Definition: vf_mcdeint.c:282

Add an element of to a dynamic array.

The array is reallocated when its number of elements reaches powers of 2. Therefore, the amortized cost of adding an element is constant.

In case of success, the pointer to the array is updated in order to point to the new grown array, and the size is incremented.

Parameters
av_size_maxmaximum size of the array, usually the MAX macro of the type of the size
av_elt_sizesize of the elements in the array, in bytes
av_arraypointer to the array, must be a lvalue
av_sizesize of the array, must be an integer lvalue
av_successstatement to execute on success; at this point, the size variable is not yet incremented
av_failurestatement to execute on failure; if this happens, the array and size are not changed; the statement can end with a return or a goto

Definition at line 45 of file dynarray.h.

Referenced by av_dynarray2_add(), av_dynarray_add(), and av_dynarray_add_nofree().