CoCalc provides the best real-time collaborative environment for Jupyter Notebooks, LaTeX documents, and SageMath, scalable from individual users to large groups and classes!
CoCalc provides the best real-time collaborative environment for Jupyter Notebooks, LaTeX documents, and SageMath, scalable from individual users to large groups and classes!
Path: blob/master/ext/at3_standalone/mem.h
Views: 1401
/*1* copyright (c) 2006 Michael Niedermayer <[email protected]>2*3* This file is part of FFmpeg.4*5* FFmpeg is free software; you can redistribute it and/or6* modify it under the terms of the GNU Lesser General Public7* License as published by the Free Software Foundation; either8* version 2.1 of the License, or (at your option) any later version.9*10* FFmpeg is distributed in the hope that it will be useful,11* but WITHOUT ANY WARRANTY; without even the implied warranty of12* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU13* Lesser General Public License for more details.14*15* You should have received a copy of the GNU Lesser General Public16* License along with FFmpeg; if not, write to the Free Software17* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA18*/1920#pragma once2122#include <limits.h>23#include <stdint.h>24#include <errno.h>25#include <stddef.h>2627#include "compat.h"2829/**30* Allocate a block of size bytes with alignment suitable for all31* memory accesses (including vectors if available on the CPU).32* @param size Size in bytes for the memory block to be allocated.33* @return Pointer to the allocated block, NULL if the block cannot34* be allocated.35* @see av_mallocz()36*/37void *av_malloc(size_t size);3839/**40* Allocate a block of size * nmemb bytes with av_malloc().41* @param nmemb Number of elements42* @param size Size of the single element43* @return Pointer to the allocated block, NULL if the block cannot44* be allocated.45* @see av_malloc()46*/47static inline void *av_malloc_array(size_t nmemb, size_t size)48{49if (!size || nmemb >= INT_MAX / size)50return NULL;51return av_malloc(nmemb * size);52}5354/**55* Allocate or reallocate a block of memory.56* If ptr is NULL and size > 0, allocate a new block. If57* size is zero, free the memory block pointed to by ptr.58* @param ptr Pointer to a memory block already allocated with59* av_realloc() or NULL.60* @param size Size in bytes of the memory block to be allocated or61* reallocated.62* @return Pointer to a newly-reallocated block or NULL if the block63* cannot be reallocated or the function is used to free the memory block.64* @warning Pointers originating from the av_malloc() family of functions must65* not be passed to av_realloc(). The former can be implemented using66* memalign() (or other functions), and there is no guarantee that67* pointers from such functions can be passed to realloc() at all.68* The situation is undefined according to POSIX and may crash with69* some libc implementations.70*/71void *av_realloc(void *ptr, size_t size);7273/**74* Allocate or reallocate a block of memory.75* This function does the same thing as av_realloc, except:76* - It takes two arguments and checks the result of the multiplication for77* integer overflow.78* - It frees the input block in case of failure, thus avoiding the memory79* leak with the classic "buf = realloc(buf); if (!buf) return -1;".80*/81void *av_realloc_f(void *ptr, size_t nelem, size_t elsize);8283/**84* Free a memory block which has been allocated with av_malloc(z)() or85* av_realloc().86* @param ptr Pointer to the memory block which should be freed.87* @note ptr = NULL is explicitly allowed.88* @note It is recommended that you use av_freep() instead.89* @see av_freep()90*/91void av_free(void *ptr);9293/**94* Allocate a block of size bytes with alignment suitable for all95* memory accesses (including vectors if available on the CPU) and96* zero all the bytes of the block.97* @param size Size in bytes for the memory block to be allocated.98* @return Pointer to the allocated block, NULL if it cannot be allocated.99* @see av_malloc()100*/101void *av_mallocz(size_t size);102103/**104* Allocate a block of size * nmemb bytes with av_mallocz().105* @param nmemb Number of elements106* @param size Size of the single element107* @return Pointer to the allocated block, NULL if the block cannot108* be allocated.109* @see av_mallocz()110* @see av_malloc_array()111*/112static inline void *av_mallocz_array(size_t nmemb, size_t size)113{114if (!size || nmemb >= INT_MAX / size)115return NULL;116return av_mallocz(nmemb * size);117}118119/**120* Free a memory block which has been allocated with av_malloc(z)() or121* av_realloc() and set the pointer pointing to it to NULL.122* @param ptr Pointer to the pointer to the memory block which should123* be freed.124* @note passing a pointer to a NULL pointer is safe and leads to no action.125* @see av_free()126*/127void av_freep(void *ptr);128129/**130* @}131*/132133134