diff options
author | Stefano Sabatini <stefasab@gmail.com> | 2013-04-14 03:07:54 +0200 |
---|---|---|
committer | Stefano Sabatini <stefasab@gmail.com> | 2013-05-13 13:52:31 +0200 |
commit | e3984166a49f708d255eecce44824f77f160781e (patch) | |
tree | 7918a1ec6f65ecef1a36509679371db661349710 /libavutil/mem.h | |
parent | 84be80698227366d970e045001e4b59e4f99f0a1 (diff) | |
download | ffmpeg-e3984166a49f708d255eecce44824f77f160781e.tar.gz |
lavu/mem: add av_dynarray2_add()
Based on a patch by Clément Bœsch.
See thread:
From: Clément Bœsch <ubitux@gmail.com>
Subject: [FFmpeg-devel] [PATCH 1/5] lavu: add av_dynarray_alloc_elem().
Date: Sun, 14 Apr 2013 03:07:54 +0200
Diffstat (limited to 'libavutil/mem.h')
-rw-r--r-- | libavutil/mem.h | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/libavutil/mem.h b/libavutil/mem.h index 8433ada1e8..a3294690cf 100644 --- a/libavutil/mem.h +++ b/libavutil/mem.h @@ -215,10 +215,35 @@ void av_freep(void *ptr); * @param tab_ptr pointer to the array to grow * @param nb_ptr pointer to the number of elements in the array * @param elem element to add + * @see av_dynarray2_add() */ void av_dynarray_add(void *tab_ptr, int *nb_ptr, void *elem); /** + * 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. + * + * @param tab_ptr pointer to the array to grow + * @param nb_ptr pointer to the number of elements in the array + * @param elem_size size in bytes of the elements in the array + * @param elem_data pointer to the data of the element to add. If NULL, the space of + * the new added element is not filled. + * @return pointer to the data of the element to copy in the new allocated space. + * If NULL, the new allocated space is left uninitialized." + * @see av_dynarray_add() + */ +void *av_dynarray2_add(void **tab_ptr, int *nb_ptr, size_t elem_size, + const uint8_t *elem_data); + +/** * Multiply two size_t values checking for overflow. * @return 0 if success, AVERROR(EINVAL) if overflow. */ |