memory handling functions
More...
#include "attributes.h"
#include "error.h"
#include "avutil.h"
Go to the source code of this file.
Defines |
#define | DECLARE_ALIGNED(n, t, v) t v |
#define | DECLARE_ASM_CONST(n, t, v) static const t v |
#define | av_malloc_attrib |
#define | av_alloc_size(n) |
#define | FF_INTERNAL_MEM_TYPE unsigned int |
#define | FF_INTERNAL_MEM_TYPE_MAX_VALUE UINT_MAX |
Functions |
void * | av_malloc (FF_INTERNAL_MEM_TYPE size) av_malloc_attrib av_alloc_size(1) |
| Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if available on the CPU).
|
void * | av_realloc (void *ptr, FF_INTERNAL_MEM_TYPE size) av_alloc_size(2) |
| Allocate or reallocate a block of memory.
|
void * | av_realloc_f (void *ptr, size_t nelem, size_t elsize) |
| Allocate or reallocate a block of memory.
|
void | av_free (void *ptr) |
| Free a memory block which has been allocated with av_malloc(z)() or av_realloc().
|
void * | av_mallocz (FF_INTERNAL_MEM_TYPE size) av_malloc_attrib av_alloc_size(1) |
| Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if available on the CPU) and zero all the bytes of the block.
|
void * | av_calloc (size_t nmemb, size_t size) av_malloc_attrib |
| Allocate a block of nmemb * size bytes with alignment suitable for all memory accesses (including vectors if available on the CPU) and zero all the bytes of the block.
|
char * | av_strdup (const char *s) av_malloc_attrib |
| Duplicate the string s.
|
void | av_freep (void *ptr) |
| Free a memory block which has been allocated with av_malloc(z)() or av_realloc() and set the pointer pointing to it to NULL.
|
void | av_dynarray_add (void *tab_ptr, int *nb_ptr, void *elem) |
| Add an element to a dynamic array.
|
static int | av_size_mult (size_t a, size_t b, size_t *r) |
| Multiply two size_t values checking for overflow.
|
Detailed Description
memory handling functions
Definition in file mem.h.
Define Documentation
#define av_alloc_size |
( |
|
n |
) |
|
Definition at line 63 of file mem.h.
Definition at line 57 of file mem.h.
#define DECLARE_ALIGNED |
( |
|
n, |
|
|
|
t, |
|
|
|
v | |
|
) |
| | t v |
Definition at line 50 of file mem.h.
#define DECLARE_ASM_CONST |
( |
|
n, |
|
|
|
t, |
|
|
|
v | |
|
) |
| | static const t v |
Definition at line 51 of file mem.h.
#define FF_INTERNAL_MEM_TYPE unsigned int |
Definition at line 67 of file mem.h.
#define FF_INTERNAL_MEM_TYPE_MAX_VALUE UINT_MAX |
Definition at line 68 of file mem.h.
Function Documentation
void* av_calloc |
( |
size_t |
nmemb, |
|
|
size_t |
size | |
|
) |
| | |
Allocate a block of nmemb * size bytes with alignment suitable for all memory accesses (including vectors if available on the CPU) and zero all the bytes of the block.
The allocation will fail if nmemb * size is greater than or equal to INT_MAX.
- Parameters:
-
- Returns:
- Pointer to the allocated block, NULL if it cannot be allocated.
Definition at line 188 of file mem.c.
void av_dynarray_add |
( |
void * |
tab_ptr, |
|
|
int * |
nb_ptr, |
|
|
void * |
elem | |
|
) |
| | |
Add an element to a dynamic array.
- Parameters:
-
| tab_ptr | Pointer to the array. |
| nb_ptr | Pointer to the number of elements in the array. |
| elem | Element to be added. |
Definition at line 208 of file mem.c.
void av_free |
( |
void * |
ptr |
) |
|
Free a memory block which has been allocated with av_malloc(z)() or av_realloc().
- Parameters:
-
| ptr | Pointer to the memory block which should be freed. |
- Note:
- ptr = NULL is explicitly allowed.
-
It is recommended that you use av_freep() instead.
- See also:
- av_freep()
Definition at line 163 of file mem.c.
void av_freep |
( |
void * |
ptr |
) |
|
Free a memory block which has been allocated with av_malloc(z)() or av_realloc() and set the pointer pointing to it to NULL.
- Parameters:
-
| ptr | Pointer to the pointer to the memory block which should be freed. |
- See also:
- av_free()
Definition at line 173 of file mem.c.
void* av_malloc |
( |
FF_INTERNAL_MEM_TYPE |
size |
) |
|
Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if available on the CPU).
- Parameters:
-
| size | Size in bytes for the memory block to be allocated. |
- Returns:
- Pointer to the allocated block, NULL if the block cannot be allocated.
- See also:
- av_mallocz()
Definition at line 70 of file mem.c.
void* av_mallocz |
( |
FF_INTERNAL_MEM_TYPE |
size |
) |
|
Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if available on the CPU) and zero all the bytes of the block.
- Parameters:
-
| size | Size in bytes for the memory block to be allocated. |
- Returns:
- Pointer to the allocated block, NULL if it cannot be allocated.
- See also:
- av_malloc()
Definition at line 180 of file mem.c.
void* av_realloc |
( |
void * |
ptr, |
|
|
FF_INTERNAL_MEM_TYPE |
size | |
|
) |
| | |
Allocate or reallocate a block of memory.
If ptr is NULL and size > 0, allocate a new block. If size is zero, free the memory block pointed to by ptr.
- Parameters:
-
| size | Size in bytes for the memory block to be allocated or reallocated. |
| ptr | Pointer to a memory block already allocated with av_malloc(z)() or av_realloc() or NULL. |
- Returns:
- Pointer to a newly reallocated block or NULL if the block cannot be reallocated or the function is used to free the memory block.
- See also:
- av_fast_realloc()
Definition at line 126 of file mem.c.
void* av_realloc_f |
( |
void * |
ptr, |
|
|
size_t |
nelem, |
|
|
size_t |
elsize | |
|
) |
| | |
Allocate or reallocate a block of memory.
This function does the same thing as av_realloc, except:
- It takes two arguments and checks the result of the multiplication for integer overflow.
- It frees the input block in case of failure, thus avoiding the memory leak with the classic "buf = realloc(buf); if (!buf) return -1;".
Definition at line 148 of file mem.c.
static int av_size_mult |
( |
size_t |
a, |
|
|
size_t |
b, |
|
|
size_t * |
r | |
|
) |
| | [inline, static] |
Multiply two size_t values checking for overflow.
- Returns:
- 0 if success, AVERROR(EINVAL) if overflow.
Definition at line 170 of file mem.h.
char* av_strdup |
( |
const char * |
s |
) |
|
Duplicate the string s.
- Parameters:
-
| s | string to be duplicated |
- Returns:
- Pointer to a newly allocated string containing a copy of s or NULL if the string cannot be allocated.
Definition at line 195 of file mem.c.