1 /* GLIB sliced memory - fast threaded memory chunk allocator
2 * Copyright (C) 2005 Tim Janik
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.
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.
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.
23 #if !defined (__GLIB_H_INSIDE__) && !defined (GLIB_COMPILATION)
24 #error "Only <glib.h> can be included directly."
27 #include <glib/gtypes.h>
31 /* slices - fast allocation/release of small memory blocks
34 gpointer
g_slice_alloc (gsize block_size
) G_GNUC_MALLOC
G_GNUC_ALLOC_SIZE(1);
36 gpointer
g_slice_alloc0 (gsize block_size
) G_GNUC_MALLOC
G_GNUC_ALLOC_SIZE(1);
38 gpointer
g_slice_copy (gsize block_size
,
39 gconstpointer mem_block
) G_GNUC_MALLOC
G_GNUC_ALLOC_SIZE(1);
41 void g_slice_free1 (gsize block_size
,
44 void g_slice_free_chain_with_offset (gsize block_size
,
47 #define g_slice_new(type) ((type*) g_slice_alloc (sizeof (type)))
48 #define g_slice_new0(type) ((type*) g_slice_alloc0 (sizeof (type)))
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.
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)); \
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)); \
76 /* --- internal debugging API --- */
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
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
);
95 void g_slice_debug_tree_statistics (void);
100 #endif /* __G_SLICE_H__ */