• Main Page
  • Related Pages
  • Modules
  • Data Structures
  • Files
  • 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 
00039 #if defined(__INTEL_COMPILER) && __INTEL_COMPILER < 1110 || defined(__SUNPRO_C)
00040     #define DECLARE_ALIGNED(n,t,v)      t __attribute__ ((aligned (n))) v
00041     #define DECLARE_ASM_CONST(n,t,v)    const t __attribute__ ((aligned (n))) v
00042 #elif defined(__TI_COMPILER_VERSION__)
00043     #define DECLARE_ALIGNED(n,t,v)                      \
00044         AV_PRAGMA(DATA_ALIGN(v,n))                      \
00045         t __attribute__((aligned(n))) v
00046     #define DECLARE_ASM_CONST(n,t,v)                    \
00047         AV_PRAGMA(DATA_ALIGN(v,n))                      \
00048         static const t __attribute__((aligned(n))) v
00049 #elif defined(__GNUC__)
00050     #define DECLARE_ALIGNED(n,t,v)      t __attribute__ ((aligned (n))) v
00051     #define DECLARE_ASM_CONST(n,t,v)    static const t av_used __attribute__ ((aligned (n))) v
00052 #elif defined(_MSC_VER)
00053     #define DECLARE_ALIGNED(n,t,v)      __declspec(align(n)) t v
00054     #define DECLARE_ASM_CONST(n,t,v)    __declspec(align(n)) static const t v
00055 #else
00056     #define DECLARE_ALIGNED(n,t,v)      t v
00057     #define DECLARE_ASM_CONST(n,t,v)    static const t v
00058 #endif
00059 
00060 #if AV_GCC_VERSION_AT_LEAST(3,1)
00061     #define av_malloc_attrib __attribute__((__malloc__))
00062 #else
00063     #define av_malloc_attrib
00064 #endif
00065 
00066 #if AV_GCC_VERSION_AT_LEAST(4,3)
00067     #define av_alloc_size(n) __attribute__((alloc_size(n)))
00068 #else
00069     #define av_alloc_size(n)
00070 #endif
00071 
00080 void *av_malloc(size_t size) av_malloc_attrib av_alloc_size(1);
00081 
00094 void *av_realloc(void *ptr, size_t size) av_alloc_size(2);
00095 
00104 void *av_realloc_f(void *ptr, size_t nelem, size_t elsize);
00105 
00114 void av_free(void *ptr);
00115 
00124 void *av_mallocz(size_t size) av_malloc_attrib av_alloc_size(1);
00125 
00136 void *av_calloc(size_t nmemb, size_t size) av_malloc_attrib;
00137 
00144 char *av_strdup(const char *s) av_malloc_attrib;
00145 
00153 void av_freep(void *ptr);
00154 
00162 void av_dynarray_add(void *tab_ptr, int *nb_ptr, void *elem);
00163 
00168 static inline int av_size_mult(size_t a, size_t b, size_t *r)
00169 {
00170     size_t t = a * b;
00171     /* Hack inspired from glibc: only try the division if nelem and elsize
00172      * are both greater than sqrt(SIZE_MAX). */
00173     if ((a | b) >= ((size_t)1 << (sizeof(size_t) * 4)) && a && t / a != b)
00174         return AVERROR(EINVAL);
00175     *r = t;
00176     return 0;
00177 }
00178 
00182 void av_max_alloc(size_t max);
00183 
00188 #endif /* AVUTIL_MEM_H */
Generated on Fri Feb 1 2013 14:34:27 for FFmpeg by doxygen 1.7.1