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_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

Definition at line 78 of file mem.c.

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

◆ av_calloc()

void* av_calloc ( size_t  nmemb,
size_t  size 
)
Examples
remux.c, and transcode.c.

Definition at line 262 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(), aribcaption_trans_bitmap_subtitle(), aribcaption_trans_text_subtitle(), 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_executor_alloc(), av_frame_ref(), av_samples_alloc_array_and_samples(), avformat_find_stream_info(), blockdetect_config_input(), blurdetect_config_input(), bonk_init(), 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(), codec_parameters_copy_side_data(), compute_kernel(), config_audio_output(), config_eq_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(), copy_av_subtitle(), create_vorbis_context(), crossover_setup(), D(), decode_entropy_coded_image(), decode_frame_header(), decode_init(), decode_main_header(), decode_picture_header(), 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_cavs_init_top_lines(), ff_ebur128_init(), ff_er_frame_end(), 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_decode_htj2k(), ff_jpeg2000_init_component(), ff_jpeg2000_tag_tree_init(), ff_make_channel_layout_list(), ff_mjpeg_decode_sof(), ff_mov_get_layout_from_channel_positions(), ff_mpv_init_context_frame(), ff_opus_parse_extradata(), ff_pca_init(), ff_psy_init(), ff_psy_preprocess_init(), ff_qsv_enc_init(), ff_qsvvpp_init(), ff_slice_buffer_init(), ff_slice_thread_allocz_entries(), ff_slice_thread_init_progress(), ff_snow_alloc_blocks(), ff_snow_common_init_after_header(), ff_vc2enc_init_transforms(), ff_vk_exec_pipeline_register(), ff_vk_exec_pool_init(), ff_vk_load_props(), ff_vk_pipeline_descriptor_set_add(), ffurl_get_protocols(), fill_model_input_tf(), find_component(), find_device(), fir_to_phase(), forward(), g722_encode_init(), gdv_decode_init(), get_audio_buffer(), get_buffer(), get_codecs_sorted(), get_histogram(), get_power(), get_siz(), graph_config_pointers(), graphs_build(), h264_init_context(), hcom_init(), hdr_encode_init(), hds_write_header(), hls_slice_data_wpp(), huf_uncompress(), hwframe_pool_prealloc(), ico_write_header(), infer_completion_callback(), init(), init_band(), init_bundles(), init_chordset(), init_cqt(), init_filter_param(), init_parse_context(), init_pattern_from_file(), init_pattern_from_string(), init_prec(), init_segment(), init_tiles(), init_vpp_session(), init_vulkan(), interpolate(), interpolate_pchip(), inverse(), ism_write_header(), ivi_init_tiles(), join_config_output(), join_init(), jpeg2000_decode_ht_cleanup_segment(), jpeg2000_decode_packet(), laf_read_header(), libopus_encode_init(), libx265_encode_set_roi(), load_data(), magy_encode_init(), main(), make_lpf(), map_init(), merge_channel_layouts_internal(), mkv_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(), osq_init(), overlay_qsv_init(), parse_chunk_headers(), parse_mapping(), parse_models(), pdv_read_header(), pic_arrays_init(), preload_sofa(), process_frame(), 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(), qsv_stack_init(), qsvvpp_init_vpp_session(), qtrle_encode_init(), read_channels(), read_distribution_bundle(), 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_dispositions(), set_enable_expr(), set_gauss(), set_roi_map(), setup_derivative_buffers(), setup_find_stream_info_opts(), setup_mb_info(), setup_roi(), stack_init(), subband_bufer_alloc(), swri_realloc_audio(), swri_rematrix_init(), tiff_decode_tag(), tm2_build_huff_table(), tq_alloc(), track_index(), try_push_frame(), uri_table_map(), vaapi_encode_issue(), vaapi_stack_init(), vc2_encode_init(), vorbis_parse_id_hdr(), vorbis_parse_setup_hdr_codebooks(), vorbis_parse_setup_hdr_floors(), vorbis_parse_setup_hdr_mappings(), vulkan_device_init(), wavarc_init(), wavesynth_parse_extradata(), X264_init(), and xmv_read_header().

◆ fill16()

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

Definition at line 359 of file mem.c.

Referenced by av_memcpy_backptr().

◆ fill24()

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

Definition at line 377 of file mem.c.

Referenced by av_memcpy_backptr().

◆ fill32()

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

Definition at line 417 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 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 = 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().