gslice.h

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

Copyright © Nokia Corporation 2001-2008
Back to top