878
|
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 #define _XOPEN_SOURCE 600
|
|
33 #include <stdlib.h>
|
|
34
|
|
35 /* you can redefine av_malloc and av_free in your project to use your
|
|
36 memory allocator. You do not need to suppress this file because the
|
|
37 linker will do it automatically */
|
|
38
|
|
39 /**
|
|
40 * Memory allocation of size byte with alignment suitable for all
|
|
41 * memory accesses (including vectors if available on the
|
|
42 * CPU). av_malloc(0) must return a non NULL pointer.
|
|
43 */
|
|
44 void *av_malloc(unsigned int size)
|
|
45 {
|
|
46 void *ptr;
|
|
47
|
|
48 #ifdef __GLIBC__
|
963
|
49 if(posix_memalign(&ptr, 16, size))
|
|
50 return NULL;
|
878
|
51 #else
|
|
52 ptr = malloc(size);
|
|
53 #endif
|
|
54
|
|
55 return ptr;
|
|
56 }
|
|
57
|
|
58 /**
|
|
59 * av_realloc semantics (same as glibc): if ptr is NULL and size > 0,
|
|
60 * identical to malloc(size). If size is zero, it is identical to
|
|
61 * free(ptr) and NULL is returned.
|
|
62 */
|
|
63 void *av_realloc(void *ptr, unsigned int size)
|
|
64 {
|
|
65 return realloc(ptr, size);
|
|
66 }
|
|
67
|
|
68 /**
|
|
69 * Free memory which has been allocated with av_malloc(z)() or av_realloc().
|
|
70 * NOTE: ptr = NULL is explicetly allowed
|
|
71 * Note2: it is recommended that you use av_freep() instead
|
|
72 */
|
|
73 void av_free(void *ptr)
|
|
74 {
|
|
75 /* XXX: this test should not be needed on most libcs */
|
|
76 if (ptr)
|
|
77 free(ptr);
|
|
78 }
|
|
79
|