Blame glib/gslice.h

Packit ae235b
/* GLIB sliced memory - fast threaded memory chunk allocator
Packit ae235b
 * Copyright (C) 2005 Tim Janik
Packit ae235b
 *
Packit ae235b
 * This library is free software; you can redistribute it and/or
Packit ae235b
 * modify it under the terms of the GNU Lesser General Public
Packit ae235b
 * License as published by the Free Software Foundation; either
Packit ae235b
 * version 2.1 of the License, or (at your option) any later version.
Packit ae235b
 *
Packit ae235b
 * This library is distributed in the hope that it will be useful,
Packit ae235b
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit ae235b
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit ae235b
 * Lesser General Public License for more details.
Packit ae235b
 *
Packit ae235b
 * You should have received a copy of the GNU Lesser General Public
Packit ae235b
 * License along with this library; if not, see <http://www.gnu.org/licenses/>.
Packit ae235b
 */
Packit ae235b
Packit ae235b
#ifndef __G_SLICE_H__
Packit ae235b
#define __G_SLICE_H__
Packit ae235b
Packit ae235b
#if !defined (__GLIB_H_INSIDE__) && !defined (GLIB_COMPILATION)
Packit ae235b
#error "Only <glib.h> can be included directly."
Packit ae235b
#endif
Packit ae235b
Packit ae235b
#include <glib/gtypes.h>
Packit ae235b
Packit ae235b
G_BEGIN_DECLS
Packit ae235b
Packit ae235b
/* slices - fast allocation/release of small memory blocks
Packit ae235b
 */
Packit ae235b
GLIB_AVAILABLE_IN_ALL
Packit ae235b
gpointer g_slice_alloc          	(gsize	       block_size) G_GNUC_MALLOC G_GNUC_ALLOC_SIZE(1);
Packit ae235b
GLIB_AVAILABLE_IN_ALL
Packit ae235b
gpointer g_slice_alloc0         	(gsize         block_size) G_GNUC_MALLOC G_GNUC_ALLOC_SIZE(1);
Packit ae235b
GLIB_AVAILABLE_IN_ALL
Packit ae235b
gpointer g_slice_copy                   (gsize         block_size,
Packit ae235b
                                         gconstpointer mem_block) G_GNUC_MALLOC G_GNUC_ALLOC_SIZE(1);
Packit ae235b
GLIB_AVAILABLE_IN_ALL
Packit ae235b
void     g_slice_free1          	(gsize         block_size,
Packit ae235b
					 gpointer      mem_block);
Packit ae235b
GLIB_AVAILABLE_IN_ALL
Packit ae235b
void     g_slice_free_chain_with_offset (gsize         block_size,
Packit ae235b
					 gpointer      mem_chain,
Packit ae235b
					 gsize         next_offset);
Packit ae235b
#define  g_slice_new(type)      ((type*) g_slice_alloc (sizeof (type)))
Packit ae235b
#define  g_slice_new0(type)     ((type*) g_slice_alloc0 (sizeof (type)))
Packit ae235b
/* MemoryBlockType *
Packit ae235b
 *       g_slice_dup                    (MemoryBlockType,
Packit ae235b
 *	                                 MemoryBlockType *mem_block);
Packit ae235b
 *       g_slice_free                   (MemoryBlockType,
Packit ae235b
 *	                                 MemoryBlockType *mem_block);
Packit ae235b
 *       g_slice_free_chain             (MemoryBlockType,
Packit ae235b
 *                                       MemoryBlockType *first_chain_block,
Packit ae235b
 *                                       memory_block_next_field);
Packit ae235b
 * pseudo prototypes for the macro
Packit ae235b
 * definitions following below.
Packit ae235b
 */
Packit ae235b
Packit ae235b
/* we go through extra hoops to ensure type safety */
Packit ae235b
#define g_slice_dup(type, mem)                                  \
Packit ae235b
  (1 ? (type*) g_slice_copy (sizeof (type), (mem))              \
Packit ae235b
     : ((void) ((type*) 0 == (mem)), (type*) 0))
Packit ae235b
#define g_slice_free(type, mem)                                 \
Packit ae235b
G_STMT_START {                                                  \
Packit ae235b
  if (1) g_slice_free1 (sizeof (type), (mem));			\
Packit ae235b
  else   (void) ((type*) 0 == (mem)); 				\
Packit ae235b
} G_STMT_END
Packit ae235b
#define g_slice_free_chain(type, mem_chain, next)               \
Packit ae235b
G_STMT_START {                                                  \
Packit ae235b
  if (1) g_slice_free_chain_with_offset (sizeof (type),		\
Packit ae235b
                 (mem_chain), G_STRUCT_OFFSET (type, next)); 	\
Packit ae235b
  else   (void) ((type*) 0 == (mem_chain));			\
Packit ae235b
} G_STMT_END
Packit ae235b
Packit ae235b
/* --- internal debugging API --- */
Packit ae235b
typedef enum {
Packit ae235b
  G_SLICE_CONFIG_ALWAYS_MALLOC = 1,
Packit ae235b
  G_SLICE_CONFIG_BYPASS_MAGAZINES,
Packit ae235b
  G_SLICE_CONFIG_WORKING_SET_MSECS,
Packit ae235b
  G_SLICE_CONFIG_COLOR_INCREMENT,
Packit ae235b
  G_SLICE_CONFIG_CHUNK_SIZES,
Packit ae235b
  G_SLICE_CONFIG_CONTENTION_COUNTER
Packit ae235b
} GSliceConfig;
Packit ae235b
Packit ae235b
GLIB_DEPRECATED_IN_2_34
Packit ae235b
void     g_slice_set_config	   (GSliceConfig ckey, gint64 value);
Packit ae235b
GLIB_DEPRECATED_IN_2_34
Packit ae235b
gint64   g_slice_get_config	   (GSliceConfig ckey);
Packit ae235b
GLIB_DEPRECATED_IN_2_34
Packit ae235b
gint64*  g_slice_get_config_state  (GSliceConfig ckey, gint64 address, guint *n_values);
Packit ae235b
Packit ae235b
#ifdef G_ENABLE_DEBUG
Packit ae235b
GLIB_AVAILABLE_IN_ALL
Packit ae235b
void     g_slice_debug_tree_statistics (void);
Packit ae235b
#endif
Packit ae235b
Packit ae235b
G_END_DECLS
Packit ae235b
Packit ae235b
#endif /* __G_SLICE_H__ */