FFmpeg
Macros | Functions | Variables
mem.c File Reference
#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_AVX512 ? 64 : (HAVE_AVX ? 32 : 16))
 

Functions

void av_max_alloc (size_t max)
 Set the maximum size that may be allocated in one block. More...
 
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). More...
 
void * av_realloc (void *ptr, size_t size)
 Allocate, reallocate, or free a block of memory. More...
 
void * av_realloc_f (void *ptr, size_t nelem, size_t elsize)
 Allocate, reallocate, or free a block of memory. More...
 
int av_reallocp (void *ptr, size_t size)
 Allocate, reallocate, or free a block of memory through a pointer to a pointer. More...
 
void * av_malloc_array (size_t nmemb, size_t size)
 
void * av_mallocz_array (size_t nmemb, size_t size)
 
void * av_realloc_array (void *ptr, size_t nmemb, size_t size)
 
int av_reallocp_array (void *ptr, size_t nmemb, size_t size)
 Allocate, reallocate an array through a pointer to a pointer. More...
 
void av_free (void *ptr)
 Free a memory block which has been allocated with a function of av_malloc() or av_realloc() family. More...
 
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. More...
 
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. More...
 
void * av_calloc (size_t nmemb, size_t size)
 
char * av_strdup (const char *s)
 Duplicate a string. More...
 
char * av_strndup (const char *s, size_t len)
 Duplicate a substring of a string. More...
 
void * av_memdup (const void *p, size_t size)
 Duplicate a buffer with av_malloc(). More...
 
int av_dynarray_add_nofree (void *tab_ptr, int *nb_ptr, void *elem)
 Add an element to a dynamic array. More...
 
void av_dynarray_add (void *tab_ptr, int *nb_ptr, void *elem)
 Add the pointer to an element to a dynamic array. More...
 
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. More...
 
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. More...
 
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. More...
 
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. More...
 
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. More...
 
int av_size_mult (size_t a, size_t b, size_t *r)
 Multiply two size_t values checking for overflow. More...
 

Variables

static atomic_size_t max_alloc_size = ATOMIC_VAR_INIT(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_AVX512 ? 64 : (HAVE_AVX ? 32 : 16))

Definition at line 65 of file mem.c.

Function Documentation

◆ size_mult()

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

◆ av_mallocz_array()

void* av_mallocz_array ( size_t  nmemb,
size_t  size 
)

Definition at line 216 of file mem.c.

◆ av_calloc()

void* av_calloc ( size_t  nmemb,
size_t  size 
)
Examples
remuxing.c, and transcoding.c.

Definition at line 272 of file mem.c.

Referenced by a64multi_encode_init(), aax_read_header(), add_filter(), alloc_buffers(), alloc_lut(), alloc_metrics(), alloc_sequence_buffers(), alloc_slice(), allocate_buffers(), allocate_model(), allocate_plane(), allocate_tables(), ap_init(), atrac3_decode_init(), atrac3p_decode_init(), audio_get_buffer(), av_audio_fifo_alloc(), av_channel_layout_from_string(), av_encryption_info_alloc(), av_encryption_init_info_alloc(), av_frame_ref(), av_samples_alloc_array_and_samples(), blockdetect_config_input(), blurdetect_config_input(), build_chord_set(), build_open_gop_key_points(), cfhd_encode_init(), channelmap_filter_frame(), check_add_bytes(), check_add_left_pred(), check_add_left_pred_16(), check_add_median_pred(), check_stream_max_drift(), checkasm_check_nlmeans(), clv_decode_init(), cng_decode_init(), config_audio_output(), config_filter(), config_input(), config_input0(), config_input_ref(), config_output(), config_props(), config_video_output(), connect_ports(), context_init_threaded(), convert_coeffs(), convert_serial2parallel(), convert_sf2tf(), convert_zp2tf(), create_vorbis_context(), crossover_setup(), D(), decode_entropy_coded_image(), decode_frame_header(), decode_init(), decode_main_header(), decode_picture_header(), decode_tile_info(), decompose_zp2biquads(), dejudder_init(), delimited_dict_parse(), display_end_segment(), dnxhd_decode_init(), dxva2_init_pool(), encode_dvd_subtitles(), encode_init(), equ_init(), fastaudio_init(), ff_alloc_entries(), ff_cavs_init_top_lines(), ff_ebur128_init(), ff_ffv1_init_slice_state(), ff_filter_alloc(), ff_frame_pool_get(), ff_frame_thread_init(), ff_framesync_init(), ff_init_filters(), ff_init_vscale(), ff_ivi_init_planes(), ff_ivi_init_tiles(), ff_jpeg2000_init_component(), ff_jpeg2000_tag_tree_init(), ff_make_channel_layout_list(), ff_mjpeg_decode_sof(), ff_opus_parse_extradata(), ff_pca_init(), ff_psy_init(), ff_psy_preprocess_init(), ff_qsv_enc_init(), ff_qsvvpp_create(), ff_slice_buffer_init(), ff_slice_thread_init_progress(), ff_snow_alloc_blocks(), ff_snow_common_init_after_header(), ff_stream_side_data_copy(), ff_vc2enc_init_transforms(), ffurl_get_protocols(), fill_model_input_tf(), find_component(), find_device(), fir_to_phase(), forward(), g2m_init_buffers(), g722_encode_init(), gdv_decode_init(), get_audio_buffer(), get_buffer(), get_codecs_sorted(), get_histogram(), get_siz(), graph_config_pointers(), graphs_build(), h264_init_context(), hcom_init(), hds_write_header(), huf_uncompress(), hwframe_pool_prealloc(), ico_write_header(), init(), init_band(), init_bundles(), init_chordset(), init_cqt(), init_filter_param(), init_out_session(), init_parse_context(), init_pattern_from_file(), init_pattern_from_string(), init_prec(), init_segment(), init_tiles(), init_vpp_session(), interpolate(), inverse(), ism_write_header(), ivi_init_tiles(), join_config_output(), join_init(), jpeg2000_decode_packet(), libopus_encode_init(), libx265_encode_set_roi(), load_data(), magy_encode_init(), main(), make_lpf(), merge_channel_layouts(), mkv_init(), mlp_encode_init(), mobiclip_init(), mov_init(), mov_read_sample_encryption_info(), mov_read_sgpd(), mov_read_stsd(), mov_text_tx3g(), movie_common_init(), mp_decode_init(), mxf_compute_index_tables(), mxf_compute_ptses_fake_index(), mxf_get_sorted_table_segments(), mxf_read_primer_pack(), nut_write_header(), nvenc_setup_surfaces(), open_input_file(), open_slave(), opus_decode_init(), oscilloscope_config_input(), overlay_qsv_init(), parse_chunk_headers(), parse_mapping(), parse_models(), pic_arrays_init(), preload_sofa(), program_opencl_init(), psy_3gpp_init(), qsv_create_mids(), qsv_frames_derive_from(), qsv_frames_derive_to(), qsv_frames_init(), qsv_init_pool(), qsv_setup_mids(), qtrle_encode_init(), read_channels(), read_iplane(), read_shape_from_file(), read_tfra(), ready_codebook(), ready_residue(), reallocate_inputs(), reallocate_outputs(), rebuild_filter_bank_with_compensation(), resample_init(), rnnoise_model_from_file(), roq_encode_init(), rtsp_read_header(), sap_write_header(), save_subtitle_set(), scd_read_header(), scd_read_table(), separate_output_names(), set_enable_expr(), set_gauss(), set_roi_map(), setup_derivative_buffers(), setup_find_stream_info_opts(), subband_bufer_alloc(), swri_realloc_audio(), swri_rematrix_init(), tiff_decode_tag(), tm2_build_huff_table(), track_index(), try_push_frame(), uri_table_map(), vaapi_encode_issue(), vc2_encode_init(), vorbis_parse_id_hdr(), vorbis_parse_setup_hdr_codebooks(), vorbis_parse_setup_hdr_floors(), vorbis_parse_setup_hdr_mappings(), wavesynth_parse_extradata(), X264_frame(), and xmv_read_header().

◆ fill16()

static void fill16 ( uint8_t *  dst,
int  len 
)
static

Definition at line 369 of file mem.c.

Referenced by av_memcpy_backptr().

◆ fill24()

static void fill24 ( uint8_t *  dst,
int  len 
)
static

Definition at line 387 of file mem.c.

Referenced by av_memcpy_backptr().

◆ fill32()

static void fill32 ( uint8_t *  dst,
int  len 
)
static

Definition at line 427 of file mem.c.

Referenced by av_memcpy_backptr().

◆ fast_malloc()

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

Definition at line 535 of file mem.c.

Referenced by av_fast_malloc(), and av_fast_mallocz().

Variable Documentation

◆ max_alloc_size

atomic_size_t max_alloc_size = ATOMIC_VAR_INIT(INT_MAX)
static

Definition at line 72 of file mem.c.

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