Wireshark  2.9.0-477-g68ec514b
The Wireshark network protocol analyzer
wmem_core.h
1 /* wmem_core.h
2  * Definitions for the Wireshark Memory Manager Core
3  * Copyright 2012, Evan Huus <eapache@gmail.com>
4  *
5  * Wireshark - Network traffic analyzer
6  * By Gerald Combs <gerald@wireshark.org>
7  * Copyright 1998 Gerald Combs
8  *
9  * SPDX-License-Identifier: GPL-2.0-or-later
10  */
11 
12 #ifndef __WMEM_CORE_H__
13 #define __WMEM_CORE_H__
14 
15 #include <string.h>
16 #include <glib.h>
17 #include <ws_symbol_export.h>
18 #include "ws_attributes.h"
19 
20 #ifdef __cplusplus
21 extern "C" {
22 #endif /* __cplusplus */
23 
39 struct _wmem_allocator_t;
42 
44 typedef enum _wmem_allocator_type_t {
63 
70 WS_DLL_PUBLIC
71 void *
72 wmem_alloc(wmem_allocator_t *allocator, const size_t size)
73 G_GNUC_MALLOC;
74 
81 #define wmem_new(allocator, type) \
82  ((type*)wmem_alloc((allocator), sizeof(type)))
83 
84 #define wmem_safe_mult(A, B) \
85  ((((A) <= 0) || ((B) <= 0) || ((gsize)(A) > (G_MAXSSIZE / (gsize)(B)))) ? 0 : ((A) * (B)))
86 
94 #define wmem_alloc_array(allocator, type, num) \
95  ((type*)wmem_alloc((allocator), wmem_safe_mult(sizeof(type), num)))
96 
104 WS_DLL_PUBLIC
105 void *
106 wmem_alloc0(wmem_allocator_t *allocator, const size_t size)
107 G_GNUC_MALLOC;
108 
116 #define wmem_new0(allocator, type) \
117  ((type*)wmem_alloc0((allocator), sizeof(type)))
118 
127 #define wmem_alloc0_array(allocator, type, num) \
128  ((type*)wmem_alloc0((allocator), wmem_safe_mult(sizeof(type), (num))))
129 
140 WS_DLL_PUBLIC
141 void
142 wmem_free(wmem_allocator_t *allocator, void *ptr);
143 
153 WS_DLL_PUBLIC
154 void *
155 wmem_realloc(wmem_allocator_t *allocator, void *ptr, const size_t size)
156 G_GNUC_MALLOC;
157 
165 WS_DLL_PUBLIC
166 void
167 wmem_free_all(wmem_allocator_t *allocator);
168 
175 WS_DLL_PUBLIC
176 void
177 wmem_gc(wmem_allocator_t *allocator);
178 
184 WS_DLL_PUBLIC
185 void
187 
194 WS_DLL_PUBLIC
196 wmem_allocator_new(const wmem_allocator_type_t type);
197 
201 WS_DLL_PUBLIC
202 void
203 wmem_init(void);
204 
209 WS_DLL_PUBLIC
210 void
211 wmem_cleanup(void);
212 
215 #ifdef __cplusplus
216 }
217 #endif /* __cplusplus */
218 
219 #endif /* __WMEM_CORE_H__ */
220 
221 /*
222  * Editor modelines - http://www.wireshark.org/tools/modelines.html
223  *
224  * Local variables:
225  * c-basic-offset: 4
226  * tab-width: 8
227  * indent-tabs-mode: nil
228  * End:
229  *
230  * vi: set shiftwidth=4 tabstop=8 expandtab:
231  * :indentSize=4:tabSize=8:noTabs=true:
232  */
WS_DLL_PUBLIC void * wmem_realloc(wmem_allocator_t *allocator, void *ptr, const size_t size) G_GNUC_MALLOC
Definition: wmem_core.c:81
Definition: wmem_core.h:45
Definition: wmem_core.h:57
WS_DLL_PUBLIC void wmem_gc(wmem_allocator_t *allocator)
Definition: wmem_core.c:116
Definition: wmem_allocator.h:26
WS_DLL_PUBLIC void wmem_destroy_allocator(wmem_allocator_t *allocator)
Definition: wmem_core.c:122
Definition: wmem_core.h:53
WS_DLL_PUBLIC void wmem_free_all(wmem_allocator_t *allocator)
Definition: wmem_core.c:110
WS_DLL_PUBLIC void wmem_free(wmem_allocator_t *allocator, void *ptr)
Definition: wmem_core.c:64
WS_DLL_PUBLIC void * wmem_alloc(wmem_allocator_t *allocator, const size_t size) G_GNUC_MALLOC
Definition: wmem_core.c:34
WS_DLL_PUBLIC wmem_allocator_t * wmem_allocator_new(const wmem_allocator_type_t type)
Definition: wmem_core.c:131
_wmem_allocator_type_t
Definition: wmem_core.h:44
WS_DLL_PUBLIC void wmem_cleanup(void)
Definition: wmem_core.c:211
WS_DLL_PUBLIC void wmem_init(void)
Definition: wmem_core.c:173
Definition: wmem_core.h:49
WS_DLL_PUBLIC void * wmem_alloc0(wmem_allocator_t *allocator, const size_t size) G_GNUC_MALLOC
Definition: wmem_core.c:50
enum _wmem_allocator_type_t wmem_allocator_type_t