Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-06 08:41:18

0001 /* GLIB sliced memory - fast threaded memory chunk allocator
0002  * Copyright (C) 2005 Tim Janik
0003  *
0004  * SPDX-License-Identifier: LGPL-2.1-or-later
0005  *
0006  * This library is free software; you can redistribute it and/or
0007  * modify it under the terms of the GNU Lesser General Public
0008  * License as published by the Free Software Foundation; either
0009  * version 2.1 of the License, or (at your option) any later version.
0010  *
0011  * This library is distributed in the hope that it will be useful,
0012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
0013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0014  * Lesser General Public License for more details.
0015  *
0016  * You should have received a copy of the GNU Lesser General Public
0017  * License along with this library; if not, see <http://www.gnu.org/licenses/>.
0018  */
0019 
0020 #ifndef __G_SLICE_H__
0021 #define __G_SLICE_H__
0022 
0023 #if !defined (__GLIB_H_INSIDE__) && !defined (GLIB_COMPILATION)
0024 #error "Only <glib.h> can be included directly."
0025 #endif
0026 
0027 #include <glib/gtypes.h>
0028 #include <string.h>
0029 
0030 G_BEGIN_DECLS
0031 
0032 /* slices - fast allocation/release of small memory blocks
0033  */
0034 GLIB_AVAILABLE_IN_ALL
0035 gpointer g_slice_alloc              (gsize         block_size) G_GNUC_MALLOC G_GNUC_ALLOC_SIZE(1);
0036 GLIB_AVAILABLE_IN_ALL
0037 gpointer g_slice_alloc0             (gsize         block_size) G_GNUC_MALLOC G_GNUC_ALLOC_SIZE(1);
0038 GLIB_AVAILABLE_IN_ALL
0039 gpointer g_slice_copy                   (gsize         block_size,
0040                                          gconstpointer mem_block) G_GNUC_ALLOC_SIZE(1);
0041 GLIB_AVAILABLE_IN_ALL
0042 void     g_slice_free1              (gsize         block_size,
0043                      gpointer      mem_block);
0044 GLIB_AVAILABLE_IN_ALL
0045 void     g_slice_free_chain_with_offset (gsize         block_size,
0046                      gpointer      mem_chain,
0047                      gsize         next_offset);
0048 #define  g_slice_new(type)      ((type*) g_slice_alloc (sizeof (type)))
0049 
0050 /* Allow the compiler to inline memset(). Since the size is a constant, this
0051  * can significantly improve performance. */
0052 #if defined (__GNUC__) && (__GNUC__ >= 2) && defined (__OPTIMIZE__)
0053 #  define g_slice_new0(type)                                    \
0054   (type *) (G_GNUC_EXTENSION ({                                 \
0055     gsize __s = sizeof (type);                                  \
0056     gpointer __p;                                               \
0057     __p = g_slice_alloc (__s);                                  \
0058     memset (__p, 0, __s);                                       \
0059     __p;                                                        \
0060   }))
0061 #else
0062 #  define g_slice_new0(type)    ((type*) g_slice_alloc0 (sizeof (type)))
0063 #endif
0064 
0065 /* MemoryBlockType *
0066  *       g_slice_dup                    (MemoryBlockType,
0067  *                                   MemoryBlockType *mem_block);
0068  *       g_slice_free                   (MemoryBlockType,
0069  *                                   MemoryBlockType *mem_block);
0070  *       g_slice_free_chain             (MemoryBlockType,
0071  *                                       MemoryBlockType *first_chain_block,
0072  *                                       memory_block_next_field);
0073  * pseudo prototypes for the macro
0074  * definitions following below.
0075  */
0076 
0077 /* we go through extra hoops to ensure type safety */
0078 #define g_slice_dup(type, mem)                                  \
0079   (1 ? (type*) g_slice_copy (sizeof (type), (mem))              \
0080      : ((void) ((type*) 0 == (mem)), (type*) 0))
0081 #define g_slice_free(type, mem)                                 \
0082 G_STMT_START {                                                  \
0083   if (1) g_slice_free1 (sizeof (type), (mem));          \
0084   else   (void) ((type*) 0 == (mem));               \
0085 } G_STMT_END
0086 #define g_slice_free_chain(type, mem_chain, next)               \
0087 G_STMT_START {                                                  \
0088   if (1) g_slice_free_chain_with_offset (sizeof (type),     \
0089                  (mem_chain), G_STRUCT_OFFSET (type, next));    \
0090   else   (void) ((type*) 0 == (mem_chain));         \
0091 } G_STMT_END
0092 
0093 /* --- internal debugging API --- */
0094 typedef enum {
0095   G_SLICE_CONFIG_ALWAYS_MALLOC = 1,
0096   G_SLICE_CONFIG_BYPASS_MAGAZINES,
0097   G_SLICE_CONFIG_WORKING_SET_MSECS,
0098   G_SLICE_CONFIG_COLOR_INCREMENT,
0099   G_SLICE_CONFIG_CHUNK_SIZES,
0100   G_SLICE_CONFIG_CONTENTION_COUNTER
0101 } GSliceConfig;
0102 
0103 GLIB_DEPRECATED_IN_2_34
0104 void     g_slice_set_config    (GSliceConfig ckey, gint64 value);
0105 GLIB_DEPRECATED_IN_2_34
0106 gint64   g_slice_get_config    (GSliceConfig ckey);
0107 GLIB_DEPRECATED_IN_2_34
0108 gint64*  g_slice_get_config_state  (GSliceConfig ckey, gint64 address, guint *n_values);
0109 
0110 #ifndef __GI_SCANNER__
0111 #ifdef G_ENABLE_DEBUG
0112 GLIB_AVAILABLE_IN_ALL
0113 void     g_slice_debug_tree_statistics (void);
0114 #endif
0115 #endif
0116 
0117 G_END_DECLS
0118 
0119 #endif /* __G_SLICE_H__ */