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 #ifndef __G_MEM_H__
00028 #define __G_MEM_H__
00029
00030 #include <g_types.h>
00031
00032
00033
00034 #ifdef USE_DMALLOC
00035 #include "dmalloc.h"
00036 #endif
00037
00038 G_BEGIN_DECLS
00039
00040 typedef struct _GAllocator GAllocator;
00041 typedef struct _GMemChunk GMemChunk;
00042
00043
00044
00045
00046
00047
00048 #ifdef __DMALLOC_H__
00049 # define g_new(type, count) (ALLOC (type, count))
00050 # define g_new0(type, count) (CALLOC (type, count))
00051 # define g_renew(type, mem, count) (REALLOC (mem, type, count))
00052 #else
00053 # define g_new(type, count) \
00054 ((type *) g_malloc ((unsigned) sizeof (type) * (count)))
00055 # define g_new0(type, count) \
00056 ((type *) g_malloc0 ((unsigned) sizeof (type) * (count)))
00057 # define g_renew(type, mem, count) \
00058 ((type *) g_realloc (mem, (unsigned) sizeof (type) * (count)))
00059 #endif
00060
00061 #define g_mem_chunk_create(type, pre_alloc, alloc_type) ( \
00062 g_mem_chunk_new (#type " mem chunks (" #pre_alloc ")", \
00063 sizeof (type), \
00064 sizeof (type) * (pre_alloc), \
00065 (alloc_type)) \
00066 )
00067 #define g_chunk_new(type, chunk) ( \
00068 (type *) g_mem_chunk_alloc (chunk) \
00069 )
00070 #define g_chunk_new0(type, chunk) ( \
00071 (type *) g_mem_chunk_alloc0 (chunk) \
00072 )
00073 #define g_chunk_free(mem, mem_chunk) G_STMT_START { \
00074 g_mem_chunk_free ((mem_chunk), (mem)); \
00075 } G_STMT_END
00076
00077
00078
00079 #ifdef USE_DMALLOC
00080
00081 #define g_malloc(size) ((gpointer) MALLOC (size))
00082 #define g_malloc0(size) ((gpointer) CALLOC (char, size))
00083 #define g_realloc(mem,size) ((gpointer) REALLOC (mem, char, size))
00084 #define g_free(mem) FREE (mem)
00085
00086 #else
00087
00088 gpointer g_malloc (gulong size);
00089 gpointer g_malloc0 (gulong size);
00090 gpointer g_realloc (gpointer mem,
00091 gulong size);
00092 void g_free (gpointer mem);
00093
00094 #endif
00095
00096 void g_mem_profile (void);
00097 void g_mem_check (gpointer mem);
00098
00099
00100
00101 GAllocator* g_allocator_new (const gchar *name,
00102 guint n_preallocs);
00103 void g_allocator_free (GAllocator *allocato);
00104
00105 #define G_ALLOCATOR_LIST (1)
00106 #define G_ALLOCATOR_SLIST (2)
00107 #define G_ALLOCATOR_NODE (3)
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128 #define G_ALLOC_ONLY 1
00129 #define G_ALLOC_AND_FREE 2
00130
00131 GMemChunk* g_mem_chunk_new (gchar *name,
00132 gint atom_size,
00133 gulong area_size,
00134 gint type);
00135 void g_mem_chunk_destroy (GMemChunk *mem_chunk);
00136 gpointer g_mem_chunk_alloc (GMemChunk *mem_chunk);
00137 gpointer g_mem_chunk_alloc0 (GMemChunk *mem_chunk);
00138 void g_mem_chunk_free (GMemChunk *mem_chunk,
00139 gpointer mem);
00140 void g_mem_chunk_clean (GMemChunk *mem_chunk);
00141 void g_mem_chunk_reset (GMemChunk *mem_chunk);
00142 void g_mem_chunk_print (GMemChunk *mem_chunk);
00143 void g_mem_chunk_info (void);
00144
00145
00146
00147
00148
00149
00150
00151
00152
00153 void g_blow_chunks (void);
00154
00155 G_END_DECLS
00156
00157 #endif
00158