• Main Page
  • Related Pages
  • Modules
  • Data Structures
  • Files
  • Examples
  • File List
  • Globals

libavutil/mem.h

Go to the documentation of this file.
00001 /*
00002  * copyright (c) 2006 Michael Niedermayer <michaelni@gmx.at>
00003  *
00004  * This file is part of FFmpeg.
00005  *
00006  * FFmpeg is free software; you can redistribute it and/or
00007  * modify it under the terms of the GNU Lesser General Public
00008  * License as published by the Free Software Foundation; either
00009  * version 2.1 of the License, or (at your option) any later version.
00010  *
00011  * FFmpeg is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014  * Lesser General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU Lesser General Public
00017  * License along with FFmpeg; if not, write to the Free Software
00018  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
00019  */
00020 
00026 #ifndef AVUTIL_MEM_H
00027 #define AVUTIL_MEM_H
00028 
00029 #include "attributes.h"
00030 #include "error.h"
00031 #include "avutil.h"
00032 
00033 #if defined(__INTEL_COMPILER) && __INTEL_COMPILER < 1110 || defined(__SUNPRO_C)
00034     #define DECLARE_ALIGNED(n,t,v)      t __attribute__ ((aligned (n))) v
00035     #define DECLARE_ASM_CONST(n,t,v)    const t __attribute__ ((aligned (n))) v
00036 #elif defined(__TI_COMPILER_VERSION__)
00037     #define DECLARE_ALIGNED(n,t,v)                      \
00038         AV_PRAGMA(DATA_ALIGN(v,n))                      \
00039         t __attribute__((aligned(n))) v
00040     #define DECLARE_ASM_CONST(n,t,v)                    \
00041         AV_PRAGMA(DATA_ALIGN(v,n))                      \
00042         static const t __attribute__((aligned(n))) v
00043 #elif defined(__GNUC__)
00044     #define DECLARE_ALIGNED(n,t,v)      t __attribute__ ((aligned (n))) v
00045     #define DECLARE_ASM_CONST(n,t,v)    static const t av_used __attribute__ ((aligned (n))) v
00046 #elif defined(_MSC_VER)
00047     #define DECLARE_ALIGNED(n,t,v)      __declspec(align(n)) t v
00048     #define DECLARE_ASM_CONST(n,t,v)    __declspec(align(n)) static const t v
00049 #else
00050     #define DECLARE_ALIGNED(n,t,v)      t v
00051     #define DECLARE_ASM_CONST(n,t,v)    static const t v
00052 #endif
00053 
00054 #if AV_GCC_VERSION_AT_LEAST(3,1)
00055     #define av_malloc_attrib __attribute__((__malloc__))
00056 #else
00057     #define av_malloc_attrib
00058 #endif
00059 
00060 #if AV_GCC_VERSION_AT_LEAST(4,3)
00061     #define av_alloc_size(n) __attribute__((alloc_size(n)))
00062 #else
00063     #define av_alloc_size(n)
00064 #endif
00065 
00066 #if LIBAVUTIL_VERSION_MAJOR < 51
00067 #   define FF_INTERNAL_MEM_TYPE unsigned int
00068 #   define FF_INTERNAL_MEM_TYPE_MAX_VALUE UINT_MAX
00069 #else
00070 #   define FF_INTERNAL_MEM_TYPE size_t
00071 #   define FF_INTERNAL_MEM_TYPE_MAX_VALUE SIZE_MAX
00072 #endif
00073 
00082 void *av_malloc(FF_INTERNAL_MEM_TYPE size) av_malloc_attrib av_alloc_size(1);
00083 
00096 void *av_realloc(void *ptr, FF_INTERNAL_MEM_TYPE size) av_alloc_size(2);
00097 
00106 void *av_realloc_f(void *ptr, size_t nelem, size_t elsize);
00107 
00116 void av_free(void *ptr);
00117 
00126 void *av_mallocz(FF_INTERNAL_MEM_TYPE size) av_malloc_attrib av_alloc_size(1);
00127 
00138 void *av_calloc(size_t nmemb, size_t size) av_malloc_attrib;
00139 
00146 char *av_strdup(const char *s) av_malloc_attrib;
00147 
00155 void av_freep(void *ptr);
00156 
00164 void av_dynarray_add(void *tab_ptr, int *nb_ptr, void *elem);
00165 
00170 static inline int av_size_mult(size_t a, size_t b, size_t *r)
00171 {
00172     size_t t = a * b;
00173     /* Hack inspired from glibc: only try the division if nelem and elsize
00174      * are both greater than sqrt(SIZE_MAX). */
00175     if ((a | b) >= ((size_t)1 << (sizeof(size_t) * 4)) && a && t / a != b)
00176         return AVERROR(EINVAL);
00177     *r = t;
00178     return 0;
00179 }
00180 
00181 #endif /* AVUTIL_MEM_H */

Generated on Fri Feb 22 2013 07:24:24 for FFmpeg by  doxygen 1.7.1