Navit SVN

/work/compile/navit/src/navit/support/glib/gslice.h

00001 /* GLIB sliced memory - fast threaded memory chunk allocator
00002  * Copyright (C) 2005 Tim Janik
00003  *
00004  * This library is free software; you can redistribute it and/or
00005  * modify it under the terms of the GNU Lesser General Public
00006  * License as published by the Free Software Foundation; either
00007  * version 2 of the License, or (at your option) any later version.
00008  *
00009  * This library is distributed in the hope that it will be useful,
00010  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012  * Lesser General Public License for more details.
00013  *
00014  * You should have received a copy of the GNU Lesser General Public
00015  * License along with this library; if not, write to the
00016  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
00017  * Boston, MA 02111-1307, USA.
00018  */
00019 
00020 #if defined(G_DISABLE_SINGLE_INCLUDES) && !defined (__GLIB_H_INSIDE__) && !defined (GLIB_COMPILATION)
00021 #error "Only <glib.h> can be included directly."
00022 #endif
00023 
00024 #ifndef __G_SLICE_H__
00025 #define __G_SLICE_H__
00026 
00027 #ifndef __G_MEM_H__
00028 #error Include <glib.h> instead of <gslice.h>
00029 #endif
00030 
00031 #include <glib/gtypes.h>
00032 
00033 G_BEGIN_DECLS
00034 
00035 /* slices - fast allocation/release of small memory blocks
00036  */
00037 gpointer g_slice_alloc                  (gsize         block_size) G_GNUC_MALLOC G_GNUC_ALLOC_SIZE(1);
00038 gpointer g_slice_alloc0                 (gsize         block_size) G_GNUC_MALLOC G_GNUC_ALLOC_SIZE(1);
00039 gpointer g_slice_copy                   (gsize         block_size,
00040                                          gconstpointer mem_block) G_GNUC_MALLOC G_GNUC_ALLOC_SIZE(1);
00041 void     g_slice_free1                  (gsize         block_size,
00042                                          gpointer      mem_block);
00043 void     g_slice_free_chain_with_offset (gsize         block_size,
00044                                          gpointer      mem_chain,
00045                                          gsize         next_offset);
00046 #define  g_slice_new(type)      ((type*) g_slice_alloc (sizeof (type)))
00047 #define  g_slice_new0(type)     ((type*) g_slice_alloc0 (sizeof (type)))
00048 /* MemoryBlockType *
00049  *       g_slice_dup                    (MemoryBlockType,
00050  *                                       MemoryBlockType *mem_block);
00051  *       g_slice_free                   (MemoryBlockType,
00052  *                                       MemoryBlockType *mem_block);
00053  *       g_slice_free_chain             (MemoryBlockType,
00054  *                                       MemoryBlockType *first_chain_block,
00055  *                                       memory_block_next_field);
00056  * pseudo prototypes for the macro
00057  * definitions following below.
00058  */
00059 
00060 /* we go through extra hoops to ensure type safety */
00061 #define g_slice_dup(type, mem)                                  \
00062   (1 ? (type*) g_slice_copy (sizeof (type), (mem))              \
00063      : ((void) ((type*) 0 == (mem)), (type*) 0))
00064 #define g_slice_free(type, mem)                         do {    \
00065   if (1) g_slice_free1 (sizeof (type), (mem));                  \
00066   else   (void) ((type*) 0 == (mem));                           \
00067 } while (0)
00068 #define g_slice_free_chain(type, mem_chain, next)       do {    \
00069   if (1) g_slice_free_chain_with_offset (sizeof (type),         \
00070                  (mem_chain), G_STRUCT_OFFSET (type, next));    \
00071   else   (void) ((type*) 0 == (mem_chain));                     \
00072 } while (0)
00073 
00074 
00075 /* --- internal debugging API --- */
00076 typedef enum {
00077   G_SLICE_CONFIG_ALWAYS_MALLOC = 1,
00078   G_SLICE_CONFIG_BYPASS_MAGAZINES,
00079   G_SLICE_CONFIG_WORKING_SET_MSECS,
00080   G_SLICE_CONFIG_COLOR_INCREMENT,
00081   G_SLICE_CONFIG_CHUNK_SIZES,
00082   G_SLICE_CONFIG_CONTENTION_COUNTER
00083 } GSliceConfig;
00084 void     g_slice_set_config        (GSliceConfig ckey, gint64 value);
00085 gint64   g_slice_get_config        (GSliceConfig ckey);
00086 gint64*  g_slice_get_config_state  (GSliceConfig ckey, gint64 address, guint *n_values);
00087 
00088 G_END_DECLS
00089 
00090 #endif /* __G_SLICE_H__ */