Fix the GObject Visual Studio Projects
[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, write to the
16  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17  * Boston, MA 02111-1307, USA.
18  */
19
20 #ifndef __G_SLICE_H__
21 #define __G_SLICE_H__
22
23 #if !defined (__GLIB_H_INSIDE__) && !defined (GLIB_COMPILATION)
24 #error "Only <glib.h> can be included directly."
25 #endif
26
27 #include <glib/gtypes.h>
28
29 G_BEGIN_DECLS
30
31 /* slices - fast allocation/release of small memory blocks
32  */
33 GLIB_AVAILABLE_IN_ALL
34 gpointer g_slice_alloc                  (gsize         block_size) G_GNUC_MALLOC G_GNUC_ALLOC_SIZE(1);
35 GLIB_AVAILABLE_IN_ALL
36 gpointer g_slice_alloc0                 (gsize         block_size) G_GNUC_MALLOC G_GNUC_ALLOC_SIZE(1);
37 GLIB_AVAILABLE_IN_ALL
38 gpointer g_slice_copy                   (gsize         block_size,
39                                          gconstpointer mem_block) G_GNUC_MALLOC G_GNUC_ALLOC_SIZE(1);
40 GLIB_AVAILABLE_IN_ALL
41 void     g_slice_free1                  (gsize         block_size,
42                                          gpointer      mem_block);
43 GLIB_AVAILABLE_IN_ALL
44 void     g_slice_free_chain_with_offset (gsize         block_size,
45                                          gpointer      mem_chain,
46                                          gsize         next_offset);
47 #define  g_slice_new(type)      ((type*) g_slice_alloc (sizeof (type)))
48 #define  g_slice_new0(type)     ((type*) g_slice_alloc0 (sizeof (type)))
49 /* MemoryBlockType *
50  *       g_slice_dup                    (MemoryBlockType,
51  *                                       MemoryBlockType *mem_block);
52  *       g_slice_free                   (MemoryBlockType,
53  *                                       MemoryBlockType *mem_block);
54  *       g_slice_free_chain             (MemoryBlockType,
55  *                                       MemoryBlockType *first_chain_block,
56  *                                       memory_block_next_field);
57  * pseudo prototypes for the macro
58  * definitions following below.
59  */
60
61 /* we go through extra hoops to ensure type safety */
62 #define g_slice_dup(type, mem)                                  \
63   (1 ? (type*) g_slice_copy (sizeof (type), (mem))              \
64      : ((void) ((type*) 0 == (mem)), (type*) 0))
65 #define g_slice_free(type, mem)                         do {    \
66   if (1) g_slice_free1 (sizeof (type), (mem));                  \
67   else   (void) ((type*) 0 == (mem));                           \
68 } while (0)
69 #define g_slice_free_chain(type, mem_chain, next)       do {    \
70   if (1) g_slice_free_chain_with_offset (sizeof (type),         \
71                  (mem_chain), G_STRUCT_OFFSET (type, next));    \
72   else   (void) ((type*) 0 == (mem_chain));                     \
73 } while (0)
74
75
76 /* --- internal debugging API --- */
77 typedef enum {
78   G_SLICE_CONFIG_ALWAYS_MALLOC = 1,
79   G_SLICE_CONFIG_BYPASS_MAGAZINES,
80   G_SLICE_CONFIG_WORKING_SET_MSECS,
81   G_SLICE_CONFIG_COLOR_INCREMENT,
82   G_SLICE_CONFIG_CHUNK_SIZES,
83   G_SLICE_CONFIG_CONTENTION_COUNTER
84 } GSliceConfig;
85
86 GLIB_DEPRECATED_IN_2_34
87 void     g_slice_set_config        (GSliceConfig ckey, gint64 value);
88 GLIB_DEPRECATED_IN_2_34
89 gint64   g_slice_get_config        (GSliceConfig ckey);
90 GLIB_DEPRECATED_IN_2_34
91 gint64*  g_slice_get_config_state  (GSliceConfig ckey, gint64 address, guint *n_values);
92
93 #ifdef G_ENABLE_DEBUG
94 GLIB_AVAILABLE_IN_ALL
95 void     g_slice_debug_tree_statistics (void);
96 #endif
97
98 G_END_DECLS
99
100 #endif /* __G_SLICE_H__ */