World of Might and Magic  0.2.0
Open reimplementation of Might and Magic 6 7 8 game engine

Utilities to make an array grow when needed. Подробнее...

+ Граф связей класса Dynamic Array:

Функции

void av_dynarray_add (void *tab_ptr, int *nb_ptr, void *elem)
 
av_warn_unused_result int av_dynarray_add_nofree (void *tab_ptr, int *nb_ptr, void *elem)
 
voidav_dynarray2_add (void **tab_ptr, int *nb_ptr, size_t elem_size, const uint8_t *elem_data)
 

Подробное описание

Utilities to make an array grow when needed.

Sometimes, the programmer would want to have an array that can grow when needed. The libavutil dynamic array utilities fill that need.

libavutil supports two systems of appending elements onto a dynamically allocated array, the first one storing the pointer to the value in the array, and the second storing the value directly. In both systems, the caller is responsible for maintaining a variable containing the length of the array, as well as freeing of the array after use.

The first system stores pointers to values in a block of dynamically allocated memory. Since only pointers are stored, the function does not need to know the size of the type. Both av_dynarray_add() and av_dynarray_add_nofree() implement this system.

type **array = NULL; //< an array of pointers to values
int nb = 0; //< a variable to keep track of the length of the array
type to_be_added = ...;
type to_be_added2 = ...;
av_dynarray_add(&array, &nb, &to_be_added);
if (nb == 0)
return AVERROR(ENOMEM);
av_dynarray_add(&array, &nb, &to_be_added2);
if (nb == 0)
return AVERROR(ENOMEM);
// Now:
// nb == 2
// &to_be_added == array[0]
// &to_be_added2 == array[1]

The second system stores the value directly in a block of memory. As a result, the function has to know the size of the type. av_dynarray2_add() implements this mechanism.

type *array = NULL; //< an array of values
int nb = 0; //< a variable to keep track of the length of the array
type to_be_added = ...;
type to_be_added2 = ...;
type *addr = av_dynarray2_add((void **)&array, &nb, sizeof(*array), NULL);
if (!addr)
return AVERROR(ENOMEM);
memcpy(addr, &to_be_added, sizeof(to_be_added));
// Shortcut of the above.
type *addr = av_dynarray2_add((void **)&array, &nb, sizeof(*array),
(const void *)&to_be_added2);
if (!addr)
return AVERROR(ENOMEM);
// Now:
// nb == 2
// to_be_added == array[0]
// to_be_added2 == array[1]

Функции

◆ av_dynarray_add()

void av_dynarray_add ( void tab_ptr,
int *  nb_ptr,
void elem 
)

#include <C:/git/world-of-might-and-magic/lib/win32/x86/ffmpeg-4.2.2/include/libavutil/mem.h>

Add the pointer to an element to a dynamic array.

The array to grow is supposed to be an array of pointers to structures, and the element to add must be a pointer to an already allocated structure.

The array is reallocated when its size 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 number pointed to by nb_ptr is incremented. In case of failure, the array is freed, *tab_ptr is set to NULL and *nb_ptr is set to 0.

Аргументы
[in,out]tab_ptrPointer to the array to grow
[in,out]nb_ptrPointer to the number of elements in the array
[in]elemElement to add
См. также
av_dynarray_add_nofree(), av_dynarray2_add()

◆ av_dynarray_add_nofree()

av_warn_unused_result int av_dynarray_add_nofree ( void tab_ptr,
int *  nb_ptr,
void elem 
)

#include <C:/git/world-of-might-and-magic/lib/win32/x86/ffmpeg-4.2.2/include/libavutil/mem.h>

Add an element to a dynamic array.

Function has the same functionality as av_dynarray_add(), but it doesn't free memory on fails. It returns error code instead and leave current buffer untouched.

Возвращает
>=0 on success, negative otherwise
См. также
av_dynarray_add(), av_dynarray2_add()

◆ av_dynarray2_add()

void* av_dynarray2_add ( void **  tab_ptr,
int *  nb_ptr,
size_t  elem_size,
const uint8_t elem_data 
)

#include <C:/git/world-of-might-and-magic/lib/win32/x86/ffmpeg-4.2.2/include/libavutil/mem.h>

Add an element of size elem_size 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 number pointed to by nb_ptr is incremented. In case of failure, the array is freed, *tab_ptr is set to NULL and *nb_ptr is set to 0.

Аргументы
[in,out]tab_ptrPointer to the array to grow
[in,out]nb_ptrPointer to the number of elements in the array
[in]elem_sizeSize in bytes of an element in the array
[in]elem_dataPointer to the data of the element to add. If NULL, the space of the newly added element is allocated but left uninitialized.
Возвращает
Pointer to the data of the element to copy in the newly allocated space
См. также
av_dynarray_add(), av_dynarray_add_nofree()
av_dynarray2_add
void * av_dynarray2_add(void **tab_ptr, int *nb_ptr, size_t elem_size, const uint8_t *elem_data)
av_freep
void av_freep(void *ptr)
array
GLenum array
Definition: SDL_opengl_glext.h:6303
addr
GLenum const void * addr
Definition: SDL_opengl_glext.h:7948
type
EGLenum type
Definition: SDL_egl.h:850
av_dynarray_add
void av_dynarray_add(void *tab_ptr, int *nb_ptr, void *elem)