Simplify stereo rematrixing by only using one temporary variable. It is also
[FFMpeg-mirror/lagarith.git] / libavutil / mem.h
blob37ba276d083bcda32e2769d1e6ba09e0092e8ba5
1 /*
2 * copyright (c) 2006 Michael Niedermayer <michaelni@gmx.at>
4 * This file is part of FFmpeg.
6 * FFmpeg is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * FFmpeg is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with FFmpeg; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21 /**
22 * @file libavutil/mem.h
23 * memory handling functions
26 #ifndef AVUTIL_MEM_H
27 #define AVUTIL_MEM_H
29 #include "common.h"
31 #if defined(__ICC) || defined(__SUNPRO_C)
32 #define DECLARE_ALIGNED(n,t,v) t v __attribute__ ((aligned (n)))
33 #define DECLARE_ASM_CONST(n,t,v) const t __attribute__ ((aligned (n))) v
34 #elif defined(__GNUC__)
35 #define DECLARE_ALIGNED(n,t,v) t v __attribute__ ((aligned (n)))
36 #define DECLARE_ASM_CONST(n,t,v) static const t v attribute_used __attribute__ ((aligned (n)))
37 #elif defined(_MSC_VER)
38 #define DECLARE_ALIGNED(n,t,v) __declspec(align(n)) t v
39 #define DECLARE_ASM_CONST(n,t,v) __declspec(align(n)) static const t v
40 #else
41 #define DECLARE_ALIGNED(n,t,v) t v
42 #define DECLARE_ASM_CONST(n,t,v) static const t v
43 #endif
46 #if AV_GCC_VERSION_AT_LEAST(3,1)
47 #define av_malloc_attrib __attribute__((__malloc__))
48 #else
49 #define av_malloc_attrib
50 #endif
52 #if (!defined(__ICC) || __ICC > 1110) && AV_GCC_VERSION_AT_LEAST(4,3)
53 #define av_alloc_size(n) __attribute__((alloc_size(n)))
54 #else
55 #define av_alloc_size(n)
56 #endif
58 /**
59 * Allocates a block of size bytes with alignment suitable for all
60 * memory accesses (including vectors if available on the CPU).
61 * @param size Size in bytes for the memory block to be allocated.
62 * @return Pointer to the allocated block, NULL if the block cannot
63 * be allocated.
64 * @see av_mallocz()
66 void *av_malloc(unsigned int size) av_malloc_attrib av_alloc_size(1);
68 /**
69 * Allocates or reallocates a block of memory.
70 * If ptr is NULL and size > 0, allocates a new block. If \p
71 * size is zero, frees the memory block pointed to by ptr.
72 * @param size Size in bytes for the memory block to be allocated or
73 * reallocated.
74 * @param ptr Pointer to a memory block already allocated with
75 * av_malloc(z)() or av_realloc() or NULL.
76 * @return Pointer to a newly reallocated block or NULL if the block
77 * cannot be reallocated or the function is used to free the memory block.
78 * @see av_fast_realloc()
80 void *av_realloc(void *ptr, unsigned int size) av_alloc_size(2);
82 /**
83 * Frees a memory block which has been allocated with av_malloc(z)() or
84 * av_realloc().
85 * @param ptr Pointer to the memory block which should be freed.
86 * @note ptr = NULL is explicitly allowed.
87 * @note It is recommended that you use av_freep() instead.
88 * @see av_freep()
90 void av_free(void *ptr);
92 /**
93 * Allocates a block of size bytes with alignment suitable for all
94 * memory accesses (including vectors if available on the CPU) and
95 * zeroes all the bytes of the block.
96 * @param size Size in bytes for the memory block to be allocated.
97 * @return Pointer to the allocated block, NULL if it cannot be allocated.
98 * @see av_malloc()
100 void *av_mallocz(unsigned int size) av_malloc_attrib av_alloc_size(1);
103 * Duplicates the string s.
104 * @param s string to be duplicated
105 * @return Pointer to a newly allocated string containing a
106 * copy of s or NULL if the string cannot be allocated.
108 char *av_strdup(const char *s) av_malloc_attrib;
111 * Frees a memory block which has been allocated with av_malloc(z)() or
112 * av_realloc() and set the pointer pointing to it to NULL.
113 * @param ptr Pointer to the pointer to the memory block which should
114 * be freed.
115 * @see av_free()
117 void av_freep(void *ptr);
119 #endif /* AVUTIL_MEM_H */