1399
|
1 /*
|
|
2 * default memory allocator for libavcodec
|
|
3 * Copyright (c) 2002 Fabrice Bellard.
|
|
4 *
|
|
5 * This library is free software; you can redistribute it and/or
|
|
6 * modify it under the terms of the GNU Lesser General Public
|
|
7 * License as published by the Free Software Foundation; either
|
|
8 * version 2 of the License, or (at your option) any later version.
|
|
9 *
|
|
10 * This library is distributed in the hope that it will be useful,
|
|
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
13 * Lesser General Public License for more details.
|
|
14 *
|
|
15 * You should have received a copy of the GNU Lesser General Public
|
|
16 * License along with this library; if not, write to the Free Software
|
|
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
18 */
|
|
19
|
|
20 /**
|
|
21 * @file mem.c
|
|
22 * default memory allocator for libavcodec.
|
|
23 */
|
|
24
|
|
25 #include "avcodec.h"
|
|
26
|
|
27 /* here we can use OS dependant allocation functions */
|
|
28 #undef malloc
|
|
29 #undef free
|
|
30 #undef realloc
|
|
31
|
|
32 #ifdef HAVE_MALLOC_H
|
|
33 #include <malloc.h>
|
|
34 #endif
|
|
35
|
|
36 /* you can redefine av_malloc and av_free in your project to use your
|
|
37 memory allocator. You do not need to suppress this file because the
|
|
38 linker will do it automatically */
|
|
39
|
|
40 /**
|
|
41 * Memory allocation of size byte with alignment suitable for all
|
|
42 * memory accesses (including vectors if available on the
|
|
43 * CPU). av_malloc(0) must return a non NULL pointer.
|
|
44 */
|
|
45 void *av_malloc(unsigned int size)
|
|
46 {
|
|
47 return memalign(16,size);
|
|
48 }
|
|
49
|
|
50 /**
|
|
51 * av_realloc semantics (same as glibc): if ptr is NULL and size > 0,
|
|
52 * identical to malloc(size). If size is zero, it is identical to
|
|
53 * free(ptr) and NULL is returned.
|
|
54 */
|
|
55 void *av_realloc(void *ptr, unsigned int size)
|
|
56 {
|
|
57 return realloc(ptr, size);
|
|
58 }
|
|
59
|
|
60 /**
|
|
61 * Free memory which has been allocated with av_malloc(z)() or av_realloc().
|
|
62 * NOTE: ptr = NULL is explicetly allowed
|
|
63 * Note2: it is recommended that you use av_freep() instead
|
|
64 */
|
|
65 void av_free(void *ptr)
|
|
66 {
|
|
67 /* XXX: this test should not be needed on most libcs */
|
|
68 if (ptr)
|
|
69 free(ptr);
|
|
70 }
|
|
71
|