vp8_pick_inter_mode code cleanup
[libvpx.git] / vpx_mem / vpx_mem.h
blob749eaa42eb021c6a5da5635ec57954e6e0c99bd0
1 /*
2 * Copyright (c) 2010 The WebM project authors. All Rights Reserved.
4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
9 */
12 #ifndef __VPX_MEM_H__
13 #define __VPX_MEM_H__
15 #if defined(__uClinux__)
16 # include <lddk.h>
17 #endif
19 /* vpx_mem version info */
20 #define vpx_mem_version "2.2.1.5"
22 #define VPX_MEM_VERSION_CHIEF 2
23 #define VPX_MEM_VERSION_MAJOR 2
24 #define VPX_MEM_VERSION_MINOR 1
25 #define VPX_MEM_VERSION_PATCH 5
26 /* end - vpx_mem version info */
28 #ifndef VPX_TRACK_MEM_USAGE
29 # define VPX_TRACK_MEM_USAGE 0 /* enable memory tracking/integrity checks */
30 #endif
31 #ifndef VPX_CHECK_MEM_FUNCTIONS
32 # define VPX_CHECK_MEM_FUNCTIONS 0 /* enable basic safety checks in _memcpy,
33 _memset, and _memmove */
34 #endif
35 #ifndef REPLACE_BUILTIN_FUNCTIONS
36 # define REPLACE_BUILTIN_FUNCTIONS 0 /* replace builtin functions with their
37 vpx_ equivalents */
38 #endif
40 #include <stdlib.h>
41 #include <stddef.h>
43 #if defined(__cplusplus)
44 extern "C" {
45 #endif
48 vpx_mem_get_version()
49 provided for runtime version checking. Returns an unsigned int of the form
50 CHIEF | MAJOR | MINOR | PATCH, where the chief version number is the high
51 order byte.
53 unsigned int vpx_mem_get_version(void);
56 vpx_mem_set_heap_size(size_t size)
57 size - size in bytes for the memory manager to allocate for its heap
58 Sets the memory manager's initial heap size
59 Return:
60 0: on success
61 -1: if memory manager calls have not been included in the vpx_mem lib
62 -2: if the memory manager has been compiled to use static memory
63 -3: if the memory manager has already allocated its heap
65 int vpx_mem_set_heap_size(size_t size);
67 void *vpx_memalign(size_t align, size_t size);
68 void *vpx_malloc(size_t size);
69 void *vpx_calloc(size_t num, size_t size);
70 void *vpx_realloc(void *memblk, size_t size);
71 void vpx_free(void *memblk);
73 void *vpx_memcpy(void *dest, const void *src, size_t length);
74 void *vpx_memset(void *dest, int val, size_t length);
75 void *vpx_memmove(void *dest, const void *src, size_t count);
77 /* special memory functions */
78 void *vpx_mem_alloc(int id, size_t size, size_t align);
79 void vpx_mem_free(int id, void *mem, size_t size);
81 /* Wrappers to standard library functions. */
82 typedef void*(* g_malloc_func)(size_t);
83 typedef void*(* g_calloc_func)(size_t, size_t);
84 typedef void*(* g_realloc_func)(void *, size_t);
85 typedef void (* g_free_func)(void *);
86 typedef void*(* g_memcpy_func)(void *, const void *, size_t);
87 typedef void*(* g_memset_func)(void *, int, size_t);
88 typedef void*(* g_memmove_func)(void *, const void *, size_t);
90 int vpx_mem_set_functions(g_malloc_func g_malloc_l
91 , g_calloc_func g_calloc_l
92 , g_realloc_func g_realloc_l
93 , g_free_func g_free_l
94 , g_memcpy_func g_memcpy_l
95 , g_memset_func g_memset_l
96 , g_memmove_func g_memmove_l);
97 int vpx_mem_unset_functions(void);
100 /* some defines for backward compatibility */
101 #define DMEM_GENERAL 0
103 #define duck_memalign(X,Y,Z) vpx_memalign(X,Y)
104 #define duck_malloc(X,Y) vpx_malloc(X)
105 #define duck_calloc(X,Y,Z) vpx_calloc(X,Y)
106 #define duck_realloc vpx_realloc
107 #define duck_free vpx_free
108 #define duck_memcpy vpx_memcpy
109 #define duck_memmove vpx_memmove
110 #define duck_memset vpx_memset
112 #if REPLACE_BUILTIN_FUNCTIONS
113 # ifndef __VPX_MEM_C__
114 # define memalign vpx_memalign
115 # define malloc vpx_malloc
116 # define calloc vpx_calloc
117 # define realloc vpx_realloc
118 # define free vpx_free
119 # define memcpy vpx_memcpy
120 # define memmove vpx_memmove
121 # define memset vpx_memset
122 # endif
123 #endif
125 #if CONFIG_MEM_TRACKER
126 #include <stdarg.h>
127 /*from vpx_mem/vpx_mem_tracker.c*/
128 extern void vpx_memory_tracker_dump();
129 extern void vpx_memory_tracker_check_integrity(char *file, unsigned int line);
130 extern int vpx_memory_tracker_set_log_type(int type, char *option);
131 extern int vpx_memory_tracker_set_log_func(void *userdata,
132 void(*logfunc)(void *userdata,
133 const char *fmt, va_list args));
134 # ifndef __VPX_MEM_C__
135 # define vpx_memalign(align, size) xvpx_memalign((align), (size), __FILE__, __LINE__)
136 # define vpx_malloc(size) xvpx_malloc((size), __FILE__, __LINE__)
137 # define vpx_calloc(num, size) xvpx_calloc(num, size, __FILE__, __LINE__)
138 # define vpx_realloc(addr, size) xvpx_realloc(addr, size, __FILE__, __LINE__)
139 # define vpx_free(addr) xvpx_free(addr, __FILE__, __LINE__)
140 # define vpx_memory_tracker_check_integrity() vpx_memory_tracker_check_integrity(__FILE__, __LINE__)
141 # define vpx_mem_alloc(id,size,align) xvpx_mem_alloc(id, size, align, __FILE__, __LINE__)
142 # define vpx_mem_free(id,mem,size) xvpx_mem_free(id, mem, size, __FILE__, __LINE__)
143 # endif
145 void *xvpx_memalign(size_t align, size_t size, char *file, int line);
146 void *xvpx_malloc(size_t size, char *file, int line);
147 void *xvpx_calloc(size_t num, size_t size, char *file, int line);
148 void *xvpx_realloc(void *memblk, size_t size, char *file, int line);
149 void xvpx_free(void *memblk, char *file, int line);
150 void *xvpx_mem_alloc(int id, size_t size, size_t align, char *file, int line);
151 void xvpx_mem_free(int id, void *mem, size_t size, char *file, int line);
153 #else
154 # ifndef __VPX_MEM_C__
155 # define vpx_memory_tracker_dump()
156 # define vpx_memory_tracker_check_integrity()
157 # define vpx_memory_tracker_set_log_type(t,o) 0
158 # define vpx_memory_tracker_set_log_func(u,f) 0
159 # endif
160 #endif
162 #if !VPX_CHECK_MEM_FUNCTIONS
163 # ifndef __VPX_MEM_C__
164 # include <string.h>
165 # define vpx_memcpy memcpy
166 # define vpx_memset memset
167 # define vpx_memmove memmove
168 # endif
169 #endif
171 #ifdef VPX_MEM_PLTFRM
172 # include VPX_MEM_PLTFRM
173 #endif
175 #if defined(__cplusplus)
177 #endif
179 #endif /* __VPX_MEM_H__ */