00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 #ifndef __G_MEM_H__
00029 #define __G_MEM_H__
00030
00031 #include <_ansi.h>
00032 #include <glib/gtypes.h>
00033
00034 G_BEGIN_DECLS
00035
00036 typedef struct _GMemVTable GMemVTable;
00037
00038
00039 #if GLIB_SIZEOF_VOID_P > GLIB_SIZEOF_LONG
00040 # define G_MEM_ALIGN GLIB_SIZEOF_VOID_P
00041 #else
00042 # define G_MEM_ALIGN GLIB_SIZEOF_LONG
00043 #endif
00044
00045
00046
00047
00048 IMPORT_C gpointer g_malloc (gulong n_bytes) G_GNUC_MALLOC;
00049 IMPORT_C gpointer g_malloc0 (gulong n_bytes) G_GNUC_MALLOC;
00050 IMPORT_C gpointer g_realloc (gpointer mem,
00051 gulong n_bytes) G_GNUC_WARN_UNUSED_RESULT;
00052 IMPORT_C void g_free (gpointer mem);
00053 IMPORT_C gpointer g_try_malloc (gulong n_bytes) G_GNUC_MALLOC;
00054 IMPORT_C gpointer g_try_malloc0 (gulong n_bytes) G_GNUC_MALLOC;
00055 IMPORT_C gpointer g_try_realloc (gpointer mem,
00056 gulong n_bytes) G_GNUC_WARN_UNUSED_RESULT;
00057
00058
00059
00060
00061 #define g_new(struct_type, n_structs) \
00062 ((struct_type *) g_malloc (((gsize) sizeof (struct_type)) * ((gsize) (n_structs))))
00063 #define g_new0(struct_type, n_structs) \
00064 ((struct_type *) g_malloc0 (((gsize) sizeof (struct_type)) * ((gsize) (n_structs))))
00065 #define g_renew(struct_type, mem, n_structs) \
00066 ((struct_type *) g_realloc ((mem), ((gsize) sizeof (struct_type)) * ((gsize) (n_structs))))
00067
00068 #define g_try_new(struct_type, n_structs) \
00069 ((struct_type *) g_try_malloc (((gsize) sizeof (struct_type)) * ((gsize) (n_structs))))
00070 #define g_try_new0(struct_type, n_structs) \
00071 ((struct_type *) g_try_malloc0 (((gsize) sizeof (struct_type)) * ((gsize) (n_structs))))
00072 #define g_try_renew(struct_type, mem, n_structs) \
00073 ((struct_type *) g_try_realloc ((mem), ((gsize) sizeof (struct_type)) * ((gsize) (n_structs))))
00074
00075
00076
00077
00078
00079
00080 struct _GMemVTable
00081 {
00082 gpointer (*malloc) (gsize n_bytes);
00083 gpointer (*realloc) (gpointer mem,
00084 gsize n_bytes);
00085 void (*free) (gpointer mem);
00086
00087 gpointer (*calloc) (gsize n_blocks,
00088 gsize n_block_bytes);
00089 gpointer (*try_malloc) (gsize n_bytes);
00090 gpointer (*try_realloc) (gpointer mem,
00091 gsize n_bytes);
00092 };
00093 IMPORT_C void g_mem_set_vtable (GMemVTable *vtable);
00094 IMPORT_C gboolean g_mem_is_system_malloc (void);
00095
00096 #ifdef SYMBIAN
00097 IMPORT_C gboolean * _g_mem_gc_friendly();
00098 #endif
00099 GLIB_VAR gboolean g_mem_gc_friendly;
00100
00101
00102 #ifdef SYMBIAN
00103 IMPORT_C GMemVTable ** _glib_mem_profiler_table();
00104 #endif
00105 GLIB_VAR GMemVTable *glib_mem_profiler_table;
00106
00107 IMPORT_C void g_mem_profile (void);
00108
00109
00110
00111 #if !defined (G_DISABLE_DEPRECATED) || defined (GTK_COMPILATION) || defined (GDK_COMPILATION)
00112 typedef struct _GAllocator GAllocator;
00113 typedef struct _GMemChunk GMemChunk;
00114 #define g_mem_chunk_create(type, pre_alloc, alloc_type) ( \
00115 g_mem_chunk_new (#type " mem chunks (" #pre_alloc ")", \
00116 sizeof (type), \
00117 sizeof (type) * (pre_alloc), \
00118 (alloc_type)) \
00119 )
00120 #define g_chunk_new(type, chunk) ( \
00121 (type *) g_mem_chunk_alloc (chunk) \
00122 )
00123 #define g_chunk_new0(type, chunk) ( \
00124 (type *) g_mem_chunk_alloc0 (chunk) \
00125 )
00126 #define g_chunk_free(mem, mem_chunk) G_STMT_START { \
00127 g_mem_chunk_free ((mem_chunk), (mem)); \
00128 } G_STMT_END
00129 #define G_ALLOC_ONLY 1
00130 #define G_ALLOC_AND_FREE 2
00131 IMPORT_C GMemChunk* g_mem_chunk_new (const gchar *name,
00132 gint atom_size,
00133 gulong area_size,
00134 gint type);
00135 IMPORT_C void g_mem_chunk_destroy (GMemChunk *mem_chunk);
00136 IMPORT_C gpointer g_mem_chunk_alloc (GMemChunk *mem_chunk);
00137 IMPORT_C gpointer g_mem_chunk_alloc0 (GMemChunk *mem_chunk);
00138 IMPORT_C void g_mem_chunk_free (GMemChunk *mem_chunk,
00139 gpointer mem);
00140 IMPORT_C void g_mem_chunk_clean (GMemChunk *mem_chunk);
00141 IMPORT_C void g_mem_chunk_reset (GMemChunk *mem_chunk);
00142 IMPORT_C void g_mem_chunk_print (GMemChunk *mem_chunk);
00143 IMPORT_C void g_mem_chunk_info (void);
00144 IMPORT_C void g_blow_chunks (void);
00145 IMPORT_C GAllocator* g_allocator_new (const gchar *name,
00146 guint n_preallocs);
00147 IMPORT_C void g_allocator_free (GAllocator *allocator);
00148 #define G_ALLOCATOR_LIST (1)
00149 #define G_ALLOCATOR_SLIST (2)
00150 #define G_ALLOCATOR_NODE (3)
00151 #endif
00152
00153 G_END_DECLS
00154
00155 #endif