gslice.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. /* GLIB sliced memory - fast threaded memory chunk allocator
  2. * Copyright (C) 2005 Tim Janik
  3. *
  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.
  8. *
  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.
  13. *
  14. * You should have received a copy of the GNU Lesser General Public
  15. * License along with this library; if not, see <http://www.gnu.org/licenses/>.
  16. */
  17. #ifndef __G_SLICE_H__
  18. #define __G_SLICE_H__
  19. #if !defined (__GLIB_H_INSIDE__) && !defined (GLIB_COMPILATION)
  20. #error "Only <glib.h> can be included directly."
  21. #endif
  22. #include <glib/gtypes.h>
  23. G_BEGIN_DECLS
  24. /* slices - fast allocation/release of small memory blocks
  25. */
  26. GLIB_AVAILABLE_IN_ALL
  27. gpointer g_slice_alloc (gsize block_size) G_GNUC_MALLOC G_GNUC_ALLOC_SIZE(1);
  28. GLIB_AVAILABLE_IN_ALL
  29. gpointer g_slice_alloc0 (gsize block_size) G_GNUC_MALLOC G_GNUC_ALLOC_SIZE(1);
  30. GLIB_AVAILABLE_IN_ALL
  31. gpointer g_slice_copy (gsize block_size,
  32. gconstpointer mem_block) G_GNUC_MALLOC G_GNUC_ALLOC_SIZE(1);
  33. GLIB_AVAILABLE_IN_ALL
  34. void g_slice_free1 (gsize block_size,
  35. gpointer mem_block);
  36. GLIB_AVAILABLE_IN_ALL
  37. void g_slice_free_chain_with_offset (gsize block_size,
  38. gpointer mem_chain,
  39. gsize next_offset);
  40. #define g_slice_new(type) ((type*) g_slice_alloc (sizeof (type)))
  41. #define g_slice_new0(type) ((type*) g_slice_alloc0 (sizeof (type)))
  42. /* MemoryBlockType *
  43. * g_slice_dup (MemoryBlockType,
  44. * MemoryBlockType *mem_block);
  45. * g_slice_free (MemoryBlockType,
  46. * MemoryBlockType *mem_block);
  47. * g_slice_free_chain (MemoryBlockType,
  48. * MemoryBlockType *first_chain_block,
  49. * memory_block_next_field);
  50. * pseudo prototypes for the macro
  51. * definitions following below.
  52. */
  53. /* we go through extra hoops to ensure type safety */
  54. #define g_slice_dup(type, mem) \
  55. (1 ? (type*) g_slice_copy (sizeof (type), (mem)) \
  56. : ((void) ((type*) 0 == (mem)), (type*) 0))
  57. #define g_slice_free(type, mem) \
  58. G_STMT_START { \
  59. if (1) g_slice_free1 (sizeof (type), (mem)); \
  60. else (void) ((type*) 0 == (mem)); \
  61. } G_STMT_END
  62. #define g_slice_free_chain(type, mem_chain, next) \
  63. G_STMT_START { \
  64. if (1) g_slice_free_chain_with_offset (sizeof (type), \
  65. (mem_chain), G_STRUCT_OFFSET (type, next)); \
  66. else (void) ((type*) 0 == (mem_chain)); \
  67. } G_STMT_END
  68. /* --- internal debugging API --- */
  69. typedef enum {
  70. G_SLICE_CONFIG_ALWAYS_MALLOC = 1,
  71. G_SLICE_CONFIG_BYPASS_MAGAZINES,
  72. G_SLICE_CONFIG_WORKING_SET_MSECS,
  73. G_SLICE_CONFIG_COLOR_INCREMENT,
  74. G_SLICE_CONFIG_CHUNK_SIZES,
  75. G_SLICE_CONFIG_CONTENTION_COUNTER
  76. } GSliceConfig;
  77. GLIB_DEPRECATED_IN_2_34
  78. void g_slice_set_config (GSliceConfig ckey, gint64 value);
  79. GLIB_DEPRECATED_IN_2_34
  80. gint64 g_slice_get_config (GSliceConfig ckey);
  81. GLIB_DEPRECATED_IN_2_34
  82. gint64* g_slice_get_config_state (GSliceConfig ckey, gint64 address, guint *n_values);
  83. #ifdef G_ENABLE_DEBUG
  84. GLIB_AVAILABLE_IN_ALL
  85. void g_slice_debug_tree_statistics (void);
  86. #endif
  87. G_END_DECLS
  88. #endif /* __G_SLICE_H__ */