Wireshark 4.5.0
The Wireshark network protocol analyzer
Loading...
Searching...
No Matches
wmem_core.h
Go to the documentation of this file.
1
12#ifndef __WMEM_CORE_H__
13#define __WMEM_CORE_H__
14
15#include <stdint.h>
16#include <stdbool.h>
17#include <string.h>
18#include <glib.h>
19#include <ws_symbol_export.h>
20#include <ws_attributes.h>
21#include <ws_posix_compat.h>
22
23#ifdef __cplusplus
24extern "C" {
25#endif /* __cplusplus */
26
45
66
73WS_DLL_PUBLIC
74void *
75wmem_alloc(wmem_allocator_t *allocator, const size_t size)
76G_GNUC_MALLOC
77G_GNUC_ALLOC_SIZE(2);
78
85#define wmem_new(allocator, type) \
86 ((type*)wmem_alloc((allocator), sizeof(type)))
87
88/*
89 * Overflow-safe multiplication of the size of a type by a number of
90 * items of that type, returning 0 if the result would overflow (or
91 * if the number of elements is negative), and the product otherwise.
92 */
93#define wmem_safe_mult_type_size(type, num) \
94 ((((num) <= 0) || ((size_t)sizeof(type) > (G_MAXSSIZE / (size_t)(num)))) ? 0 : (sizeof(type) * (num)))
95
103#define wmem_alloc_array(allocator, type, num) \
104 ((type*)wmem_alloc((allocator), wmem_safe_mult_type_size(type, (num))))
105
113WS_DLL_PUBLIC
114void *
115wmem_alloc0(wmem_allocator_t *allocator, const size_t size)
116G_GNUC_MALLOC
117G_GNUC_ALLOC_SIZE(2);
118
126#define wmem_new0(allocator, type) \
127 ((type*)wmem_alloc0((allocator), sizeof(type)))
128
137#define wmem_alloc0_array(allocator, type, num) \
138 ((type*)wmem_alloc0((allocator), wmem_safe_mult_type_size(type, (num))))
139
150WS_DLL_PUBLIC
151void
152wmem_free(wmem_allocator_t *allocator, void *ptr);
153
163WS_DLL_PUBLIC
164void *
165wmem_realloc(wmem_allocator_t *allocator, void *ptr, const size_t size)
166G_GNUC_ALLOC_SIZE(3);
167
175WS_DLL_PUBLIC
176void
178
185WS_DLL_PUBLIC
186void
187wmem_gc(wmem_allocator_t *allocator);
188
194WS_DLL_PUBLIC
195void
197
204WS_DLL_PUBLIC
207
211WS_DLL_PUBLIC
212void
213wmem_init(void);
214
219WS_DLL_PUBLIC
220void
221wmem_cleanup(void);
222
223WS_DLL_PUBLIC
224void
225wmem_enter_scope(wmem_allocator_t *allocator);
226
227WS_DLL_PUBLIC
228void
229wmem_leave_scope(wmem_allocator_t *allocator);
230
231WS_DLL_PUBLIC
232bool
233wmem_in_scope(wmem_allocator_t *allocator);
234
237#ifdef __cplusplus
238}
239#endif /* __cplusplus */
240
241#endif /* __WMEM_CORE_H__ */
242
243/*
244 * Editor modelines - https://www.wireshark.org/tools/modelines.html
245 *
246 * Local variables:
247 * c-basic-offset: 4
248 * tab-width: 8
249 * indent-tabs-mode: nil
250 * End:
251 *
252 * vi: set shiftwidth=4 tabstop=8 expandtab:
253 * :indentSize=4:tabSize=8:noTabs=true:
254 */
WS_DLL_PUBLIC void wmem_init(void)
Definition wmem_core.c:168
WS_DLL_PUBLIC void wmem_free_all(wmem_allocator_t *allocator)
Definition wmem_core.c:108
WS_DLL_PUBLIC wmem_allocator_t * wmem_allocator_new(const wmem_allocator_type_t type)
Definition wmem_core.c:129
WS_DLL_PUBLIC void wmem_free(wmem_allocator_t *allocator, void *ptr)
Definition wmem_core.c:62
_wmem_allocator_type_t
Definition wmem_core.h:47
WS_DLL_PUBLIC void wmem_cleanup(void)
Definition wmem_core.c:205
WS_DLL_PUBLIC void wmem_gc(wmem_allocator_t *allocator)
Definition wmem_core.c:114
WS_DLL_PUBLIC void * wmem_realloc(wmem_allocator_t *allocator, void *ptr, const size_t size) G_GNUC_ALLOC_SIZE(3)
Definition wmem_core.c:79
WS_DLL_PUBLIC void * wmem_alloc(wmem_allocator_t *allocator, const size_t size) G_GNUC_MALLOC G_GNUC_ALLOC_SIZE(2)
Definition wmem_core.c:32
WS_DLL_PUBLIC void wmem_destroy_allocator(wmem_allocator_t *allocator)
Definition wmem_core.c:120
enum _wmem_allocator_type_t wmem_allocator_type_t
WS_DLL_PUBLIC void * wmem_alloc0(wmem_allocator_t *allocator, const size_t size) G_GNUC_MALLOC G_GNUC_ALLOC_SIZE(2)
Definition wmem_core.c:48
@ WMEM_ALLOCATOR_BLOCK
Definition wmem_core.h:52
@ WMEM_ALLOCATOR_STRICT
Definition wmem_core.h:56
@ WMEM_ALLOCATOR_SIMPLE
Definition wmem_core.h:48
@ WMEM_ALLOCATOR_BLOCK_FAST
Definition wmem_core.h:60
Definition wmem_allocator.h:27