FFmpeg
Loading...
Searching...
No Matches
mem.c File Reference

default memory allocator for libavutil More...

#include "config.h"
#include <limits.h>
#include <stdint.h>
#include <stdlib.h>
#include <stdatomic.h>
#include <string.h>
#include "attributes.h"
#include "avassert.h"
#include "dynarray.h"
#include "error.h"
#include "internal.h"
#include "intreadwrite.h"
#include "macros.h"
#include "mem.h"

Go to the source code of this file.

Macros

#define _XOPEN_SOURCE   600
#define ALIGN   (HAVE_SIMD_ALIGN_64 ? 64 : (HAVE_SIMD_ALIGN_32 ? 32 : 16))
#define FF_MEMORY_POISON   0x2a

Functions

void av_max_alloc (size_t max)
 Set the maximum size that may be allocated in one block.
static int size_mult (size_t a, size_t b, size_t *r)
void * av_malloc (size_t size)
 Allocate a memory block with alignment suitable for all memory accesses (including vectors if available on the CPU).
void * av_realloc (void *ptr, size_t size)
 Allocate, reallocate, or free a block of memory.
void * av_realloc_f (void *ptr, size_t nelem, size_t elsize)
 Allocate, reallocate, or free a block of memory.
int av_reallocp (void *ptr, size_t size)
 Allocate, reallocate, or free a block of memory through a pointer to a pointer.
void * av_malloc_array (size_t nmemb, size_t size)
 Allocate a memory block for an array with av_malloc().
void * av_realloc_array (void *ptr, size_t nmemb, size_t size)
 Allocate, reallocate, or free an array.
int av_reallocp_array (void *ptr, size_t nmemb, size_t size)
 Allocate, reallocate an array through a pointer to a pointer.
void av_free (void *ptr)
 Free a memory block which has been allocated with a function of av_malloc() or av_realloc() family.
void av_freep (void *arg)
 Free a memory block which has been allocated with a function of av_malloc() or av_realloc() family, and set the pointer pointing to it to NULL.
void * av_mallocz (size_t size)
 Allocate a memory block 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)
 Allocate a memory block for an array with av_mallocz().
char * av_strdup (const char *s)
 Duplicate a string.
char * av_strndup (const char *s, size_t len)
 Duplicate a substring of a string.
void * av_memdup (const void *p, size_t size)
 Duplicate a buffer with av_malloc().
int av_dynarray_add_nofree (void *tab_ptr, int *nb_ptr, void *elem)
 Add an element to a dynamic array.
void av_dynarray_add (void *tab_ptr, int *nb_ptr, void *elem)
 Add the pointer to an element to a dynamic array.
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.
static void fill16 (uint8_t *dst, int len)
static void fill24 (uint8_t *dst, int len)
static void fill32 (uint8_t *dst, int len)
void av_memcpy_backptr (uint8_t *dst, int back, int cnt)
 Overlapping memcpy() implementation.
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.
static void fast_malloc (void *ptr, unsigned int *size, size_t min_size, int zero_realloc)
void av_fast_malloc (void *ptr, unsigned int *size, size_t min_size)
 Allocate a buffer, reusing the given one if large enough.
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.
int av_size_mult (size_t a, size_t b, size_t *r)
 Multiply two size_t values checking for overflow.

Variables

static atomic_size_t max_alloc_size = INT_MAX

Detailed Description

default memory allocator for libavutil

Definition in file mem.c.

Macro Definition Documentation

◆ _XOPEN_SOURCE

#define _XOPEN_SOURCE   600

Definition at line 27 of file mem.c.

◆ ALIGN

#define ALIGN   (HAVE_SIMD_ALIGN_64 ? 64 : (HAVE_SIMD_ALIGN_32 ? 32 : 16))

Definition at line 65 of file mem.c.

◆ FF_MEMORY_POISON

#define FF_MEMORY_POISON   0x2a

Definition at line 67 of file mem.c.

Referenced by av_dynarray2_add(), av_malloc(), and av_realloc().

Function Documentation

◆ size_mult()

int size_mult ( size_t a,
size_t b,
size_t * r )
static

Definition at line 80 of file mem.c.

Referenced by av_calloc(), av_malloc_array(), av_realloc_array(), av_realloc_f(), and av_size_mult().

◆ fill16()

void fill16 ( uint8_t * dst,
int len )
static

Definition at line 359 of file mem.c.

Referenced by av_memcpy_backptr().

◆ fill24()

void fill24 ( uint8_t * dst,
int len )
static

Definition at line 377 of file mem.c.

Referenced by av_memcpy_backptr().

◆ fill32()

void fill32 ( uint8_t * dst,
int len )
static

Definition at line 417 of file mem.c.

Referenced by av_memcpy_backptr().

◆ fast_malloc()

void fast_malloc ( void * ptr,
unsigned int * size,
size_t min_size,
int zero_realloc )
inlinestatic

Definition at line 525 of file mem.c.

Referenced by av_fast_malloc(), and av_fast_mallocz().

Variable Documentation

◆ max_alloc_size

atomic_size_t max_alloc_size = INT_MAX
static

Definition at line 74 of file mem.c.

Referenced by av_fast_realloc(), av_malloc(), av_max_alloc(), av_realloc(), and fast_malloc().