[kdbus] KDBUS_ITEM_PAYLOAD_OFF items are (once again) relative to msg header
[platform/upstream/glib.git] / glib / gslice.h
1 /* GLIB sliced memory - fast threaded memory chunk allocator
2  * Copyright (C) 2005 Tim Janik
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, see <http://www.gnu.org/licenses/>.
16  */
17
18 #ifndef __G_SLICE_H__
19 #define __G_SLICE_H__
20
21 #if !defined (__GLIB_H_INSIDE__) && !defined (GLIB_COMPILATION)
22 #error "Only <glib.h> can be included directly."
23 #endif
24
25 #include <glib/gtypes.h>
26
27 G_BEGIN_DECLS
28
29 /* slices - fast allocation/release of small memory blocks
30  */
31 GLIB_AVAILABLE_IN_ALL
32 gpointer g_slice_alloc                  (gsize         block_size) G_GNUC_MALLOC G_GNUC_ALLOC_SIZE(1);
33 GLIB_AVAILABLE_IN_ALL
34 gpointer g_slice_alloc0                 (gsize         block_size) G_GNUC_MALLOC G_GNUC_ALLOC_SIZE(1);
35 GLIB_AVAILABLE_IN_ALL
36 gpointer g_slice_copy                   (gsize         block_size,
37                                          gconstpointer mem_block) G_GNUC_MALLOC G_GNUC_ALLOC_SIZE(1);
38 GLIB_AVAILABLE_IN_ALL
39 void     g_slice_free1                  (gsize         block_size,
40                                          gpointer      mem_block);
41 GLIB_AVAILABLE_IN_ALL
42 void     g_slice_free_chain_with_offset (gsize         block_size,
43                                          gpointer      mem_chain,
44                                          gsize         next_offset);
45 #define  g_slice_new(type)      ((type*) g_slice_alloc (sizeof (type)))
46 #define  g_slice_new0(type)     ((type*) g_slice_alloc0 (sizeof (type)))
47 /* MemoryBlockType *
48  *       g_slice_dup                    (MemoryBlockType,
49  *                                       MemoryBlockType *mem_block);
50  *       g_slice_free                   (MemoryBlockType,
51  *                                       MemoryBlockType *mem_block);
52  *       g_slice_free_chain             (MemoryBlockType,
53  *                                       MemoryBlockType *first_chain_block,
54  *                                       memory_block_next_field);
55  * pseudo prototypes for the macro
56  * definitions following below.
57  */
58
59 /* we go through extra hoops to ensure type safety */
60 #define g_slice_dup(type, mem)                                  \
61   (1 ? (type*) g_slice_copy (sizeof (type), (mem))              \
62      : ((void) ((type*) 0 == (mem)), (type*) 0))
63 #define g_slice_free(type, mem)                         do {    \
64   if (1) g_slice_free1 (sizeof (type), (mem));                  \
65   else   (void) ((type*) 0 == (mem));                           \
66 } while (0)
67 #define g_slice_free_chain(type, mem_chain, next)       do {    \
68   if (1) g_slice_free_chain_with_offset (sizeof (type),         \
69                  (mem_chain), G_STRUCT_OFFSET (type, next));    \
70   else   (void) ((type*) 0 == (mem_chain));                     \
71 } while (0)
72
73
74 /* --- internal debugging API --- */
75 typedef enum {
76   G_SLICE_CONFIG_ALWAYS_MALLOC = 1,
77   G_SLICE_CONFIG_BYPASS_MAGAZINES,
78   G_SLICE_CONFIG_WORKING_SET_MSECS,
79   G_SLICE_CONFIG_COLOR_INCREMENT,
80   G_SLICE_CONFIG_CHUNK_SIZES,
81   G_SLICE_CONFIG_CONTENTION_COUNTER
82 } GSliceConfig;
83
84 GLIB_DEPRECATED_IN_2_34
85 void     g_slice_set_config        (GSliceConfig ckey, gint64 value);
86 GLIB_DEPRECATED_IN_2_34
87 gint64   g_slice_get_config        (GSliceConfig ckey);
88 GLIB_DEPRECATED_IN_2_34
89 gint64*  g_slice_get_config_state  (GSliceConfig ckey, gint64 address, guint *n_values);
90
91 #ifdef G_ENABLE_DEBUG
92 GLIB_AVAILABLE_IN_ALL
93 void     g_slice_debug_tree_statistics (void);
94 #endif
95
96 G_END_DECLS
97
98 #endif /* __G_SLICE_H__ */