williamr@2
|
1 |
/* GLIB - Library of useful routines for C programming
|
williamr@2
|
2 |
* Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
|
williamr@2
|
3 |
* Portions copyright (c) 2006 Nokia Corporation. All rights reserved.
|
williamr@2
|
4 |
*
|
williamr@2
|
5 |
* This library is free software; you can redistribute it and/or
|
williamr@2
|
6 |
* modify it under the terms of the GNU Lesser General Public
|
williamr@2
|
7 |
* License as published by the Free Software Foundation; either
|
williamr@2
|
8 |
* version 2 of the License, or (at your option) any later version.
|
williamr@2
|
9 |
*
|
williamr@2
|
10 |
* This library is distributed in the hope that it will be useful,
|
williamr@2
|
11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
williamr@2
|
12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
williamr@2
|
13 |
* Lesser General Public License for more details.
|
williamr@2
|
14 |
*
|
williamr@2
|
15 |
* You should have received a copy of the GNU Lesser General Public
|
williamr@2
|
16 |
* License along with this library; if not, write to the
|
williamr@2
|
17 |
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
williamr@2
|
18 |
* Boston, MA 02111-1307, USA.
|
williamr@2
|
19 |
*/
|
williamr@2
|
20 |
|
williamr@2
|
21 |
/*
|
williamr@2
|
22 |
* Modified by the GLib Team and others 1997-2000. See the AUTHORS
|
williamr@2
|
23 |
* file for a list of people on the GLib Team. See the ChangeLog
|
williamr@2
|
24 |
* files for a list of changes. These files are distributed with
|
williamr@2
|
25 |
* GLib at ftp://ftp.gtk.org/pub/gtk/.
|
williamr@2
|
26 |
*/
|
williamr@2
|
27 |
|
williamr@2
|
28 |
#ifndef __G_MEM_H__
|
williamr@2
|
29 |
#define __G_MEM_H__
|
williamr@2
|
30 |
|
williamr@2
|
31 |
#include <_ansi.h>
|
williamr@2
|
32 |
#include <glib/gtypes.h>
|
williamr@2
|
33 |
|
williamr@2
|
34 |
G_BEGIN_DECLS
|
williamr@2
|
35 |
|
williamr@2
|
36 |
typedef struct _GMemVTable GMemVTable;
|
williamr@2
|
37 |
|
williamr@2
|
38 |
|
williamr@2
|
39 |
#if GLIB_SIZEOF_VOID_P > GLIB_SIZEOF_LONG
|
williamr@2
|
40 |
# define G_MEM_ALIGN GLIB_SIZEOF_VOID_P
|
williamr@2
|
41 |
#else /* GLIB_SIZEOF_VOID_P <= GLIB_SIZEOF_LONG */
|
williamr@2
|
42 |
# define G_MEM_ALIGN GLIB_SIZEOF_LONG
|
williamr@2
|
43 |
#endif /* GLIB_SIZEOF_VOID_P <= GLIB_SIZEOF_LONG */
|
williamr@2
|
44 |
|
williamr@2
|
45 |
|
williamr@2
|
46 |
/* Memory allocation functions
|
williamr@2
|
47 |
*/
|
williamr@2
|
48 |
IMPORT_C gpointer g_malloc (gulong n_bytes) G_GNUC_MALLOC;
|
williamr@2
|
49 |
IMPORT_C gpointer g_malloc0 (gulong n_bytes) G_GNUC_MALLOC;
|
williamr@2
|
50 |
IMPORT_C gpointer g_realloc (gpointer mem,
|
williamr@2
|
51 |
gulong n_bytes) G_GNUC_WARN_UNUSED_RESULT;
|
williamr@2
|
52 |
IMPORT_C void g_free (gpointer mem);
|
williamr@2
|
53 |
IMPORT_C gpointer g_try_malloc (gulong n_bytes) G_GNUC_MALLOC;
|
williamr@2
|
54 |
IMPORT_C gpointer g_try_malloc0 (gulong n_bytes) G_GNUC_MALLOC;
|
williamr@2
|
55 |
IMPORT_C gpointer g_try_realloc (gpointer mem,
|
williamr@2
|
56 |
gulong n_bytes) G_GNUC_WARN_UNUSED_RESULT;
|
williamr@2
|
57 |
|
williamr@2
|
58 |
|
williamr@2
|
59 |
/* Convenience memory allocators
|
williamr@2
|
60 |
*/
|
williamr@2
|
61 |
#define g_new(struct_type, n_structs) \
|
williamr@2
|
62 |
((struct_type *) g_malloc (((gsize) sizeof (struct_type)) * ((gsize) (n_structs))))
|
williamr@2
|
63 |
#define g_new0(struct_type, n_structs) \
|
williamr@2
|
64 |
((struct_type *) g_malloc0 (((gsize) sizeof (struct_type)) * ((gsize) (n_structs))))
|
williamr@2
|
65 |
#define g_renew(struct_type, mem, n_structs) \
|
williamr@2
|
66 |
((struct_type *) g_realloc ((mem), ((gsize) sizeof (struct_type)) * ((gsize) (n_structs))))
|
williamr@2
|
67 |
|
williamr@2
|
68 |
#define g_try_new(struct_type, n_structs) \
|
williamr@2
|
69 |
((struct_type *) g_try_malloc (((gsize) sizeof (struct_type)) * ((gsize) (n_structs))))
|
williamr@2
|
70 |
#define g_try_new0(struct_type, n_structs) \
|
williamr@2
|
71 |
((struct_type *) g_try_malloc0 (((gsize) sizeof (struct_type)) * ((gsize) (n_structs))))
|
williamr@2
|
72 |
#define g_try_renew(struct_type, mem, n_structs) \
|
williamr@2
|
73 |
((struct_type *) g_try_realloc ((mem), ((gsize) sizeof (struct_type)) * ((gsize) (n_structs))))
|
williamr@2
|
74 |
|
williamr@2
|
75 |
|
williamr@2
|
76 |
/* Memory allocation virtualization for debugging purposes
|
williamr@2
|
77 |
* g_mem_set_vtable() has to be the very first GLib function called
|
williamr@2
|
78 |
* if being used
|
williamr@2
|
79 |
*/
|
williamr@2
|
80 |
struct _GMemVTable
|
williamr@2
|
81 |
{
|
williamr@2
|
82 |
gpointer (*malloc) (gsize n_bytes);
|
williamr@2
|
83 |
gpointer (*realloc) (gpointer mem,
|
williamr@2
|
84 |
gsize n_bytes);
|
williamr@2
|
85 |
void (*free) (gpointer mem);
|
williamr@2
|
86 |
/* optional; set to NULL if not used ! */
|
williamr@2
|
87 |
gpointer (*calloc) (gsize n_blocks,
|
williamr@2
|
88 |
gsize n_block_bytes);
|
williamr@2
|
89 |
gpointer (*try_malloc) (gsize n_bytes);
|
williamr@2
|
90 |
gpointer (*try_realloc) (gpointer mem,
|
williamr@2
|
91 |
gsize n_bytes);
|
williamr@2
|
92 |
};
|
williamr@2
|
93 |
IMPORT_C void g_mem_set_vtable (GMemVTable *vtable);
|
williamr@2
|
94 |
IMPORT_C gboolean g_mem_is_system_malloc (void);
|
williamr@2
|
95 |
|
williamr@2
|
96 |
#ifdef __SYMBIAN32__
|
williamr@2
|
97 |
IMPORT_C gboolean * _g_mem_gc_friendly();
|
williamr@2
|
98 |
#endif /* __SYMBIAN32__ */
|
williamr@2
|
99 |
GLIB_VAR gboolean g_mem_gc_friendly;
|
williamr@2
|
100 |
|
williamr@2
|
101 |
/* Memory profiler and checker, has to be enabled via g_mem_set_vtable()*/
|
williamr@2
|
102 |
#ifdef __SYMBIAN32__
|
williamr@2
|
103 |
IMPORT_C GMemVTable ** _glib_mem_profiler_table();
|
williamr@2
|
104 |
#endif /* __SYMBIAN32__ */
|
williamr@2
|
105 |
GLIB_VAR GMemVTable *glib_mem_profiler_table;
|
williamr@2
|
106 |
|
williamr@2
|
107 |
IMPORT_C void g_mem_profile (void);
|
williamr@2
|
108 |
|
williamr@2
|
109 |
|
williamr@2
|
110 |
/* deprecated memchunks and allocators */
|
williamr@2
|
111 |
#if !defined (G_DISABLE_DEPRECATED) || defined (GTK_COMPILATION) || defined (GDK_COMPILATION)
|
williamr@2
|
112 |
typedef struct _GAllocator GAllocator;
|
williamr@2
|
113 |
typedef struct _GMemChunk GMemChunk;
|
williamr@2
|
114 |
#define g_mem_chunk_create(type, pre_alloc, alloc_type) ( \
|
williamr@2
|
115 |
g_mem_chunk_new (#type " mem chunks (" #pre_alloc ")", \
|
williamr@2
|
116 |
sizeof (type), \
|
williamr@2
|
117 |
sizeof (type) * (pre_alloc), \
|
williamr@2
|
118 |
(alloc_type)) \
|
williamr@2
|
119 |
)
|
williamr@2
|
120 |
#define g_chunk_new(type, chunk) ( \
|
williamr@2
|
121 |
(type *) g_mem_chunk_alloc (chunk) \
|
williamr@2
|
122 |
)
|
williamr@2
|
123 |
#define g_chunk_new0(type, chunk) ( \
|
williamr@2
|
124 |
(type *) g_mem_chunk_alloc0 (chunk) \
|
williamr@2
|
125 |
)
|
williamr@2
|
126 |
#define g_chunk_free(mem, mem_chunk) G_STMT_START { \
|
williamr@2
|
127 |
g_mem_chunk_free ((mem_chunk), (mem)); \
|
williamr@2
|
128 |
} G_STMT_END
|
williamr@2
|
129 |
#define G_ALLOC_ONLY 1
|
williamr@2
|
130 |
#define G_ALLOC_AND_FREE 2
|
williamr@2
|
131 |
IMPORT_C GMemChunk* g_mem_chunk_new (const gchar *name,
|
williamr@2
|
132 |
gint atom_size,
|
williamr@2
|
133 |
gulong area_size,
|
williamr@2
|
134 |
gint type);
|
williamr@2
|
135 |
IMPORT_C void g_mem_chunk_destroy (GMemChunk *mem_chunk);
|
williamr@2
|
136 |
IMPORT_C gpointer g_mem_chunk_alloc (GMemChunk *mem_chunk);
|
williamr@2
|
137 |
IMPORT_C gpointer g_mem_chunk_alloc0 (GMemChunk *mem_chunk);
|
williamr@2
|
138 |
IMPORT_C void g_mem_chunk_free (GMemChunk *mem_chunk,
|
williamr@2
|
139 |
gpointer mem);
|
williamr@2
|
140 |
IMPORT_C void g_mem_chunk_clean (GMemChunk *mem_chunk);
|
williamr@2
|
141 |
IMPORT_C void g_mem_chunk_reset (GMemChunk *mem_chunk);
|
williamr@2
|
142 |
IMPORT_C void g_mem_chunk_print (GMemChunk *mem_chunk);
|
williamr@2
|
143 |
IMPORT_C void g_mem_chunk_info (void);
|
williamr@2
|
144 |
IMPORT_C void g_blow_chunks (void);
|
williamr@2
|
145 |
IMPORT_C GAllocator* g_allocator_new (const gchar *name,
|
williamr@2
|
146 |
guint n_preallocs);
|
williamr@2
|
147 |
IMPORT_C void g_allocator_free (GAllocator *allocator);
|
williamr@2
|
148 |
#define G_ALLOCATOR_LIST (1)
|
williamr@2
|
149 |
#define G_ALLOCATOR_SLIST (2)
|
williamr@2
|
150 |
#define G_ALLOCATOR_NODE (3)
|
williamr@2
|
151 |
#endif /* G_DISABLE_DEPRECATED */
|
williamr@2
|
152 |
|
williamr@2
|
153 |
G_END_DECLS
|
williamr@2
|
154 |
|
williamr@2
|
155 |
#endif /* __G_MEM_H__ */
|