* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the
- * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- * Boston, MA 02111-1307, USA.
+ * License along with this library; if not, see <http://www.gnu.org/licenses/>.
*/
/*
* GLib at ftp://ftp.gtk.org/pub/gtk/.
*/
-#if defined(G_DISABLE_SINGLE_INCLUDES) && !defined (__GLIB_H_INSIDE__) && !defined (GLIB_COMPILATION)
-#error "Only <glib.h> can be included directly."
-#endif
-
#ifndef __G_MEM_H__
#define __G_MEM_H__
-#include <glib/gslice.h>
+#if !defined (__GLIB_H_INSIDE__) && !defined (GLIB_COMPILATION)
+#error "Only <glib.h> can be included directly."
+#endif
+
#include <glib/gtypes.h>
G_BEGIN_DECLS
/* Memory allocation functions
*/
+GLIB_AVAILABLE_IN_ALL
void g_free (gpointer mem);
+GLIB_AVAILABLE_IN_2_34
+void g_clear_pointer (gpointer *pp,
+ GDestroyNotify destroy);
+
+GLIB_AVAILABLE_IN_ALL
gpointer g_malloc (gsize n_bytes) G_GNUC_MALLOC G_GNUC_ALLOC_SIZE(1);
+GLIB_AVAILABLE_IN_ALL
gpointer g_malloc0 (gsize n_bytes) G_GNUC_MALLOC G_GNUC_ALLOC_SIZE(1);
+GLIB_AVAILABLE_IN_ALL
gpointer g_realloc (gpointer mem,
gsize n_bytes) G_GNUC_WARN_UNUSED_RESULT;
+GLIB_AVAILABLE_IN_ALL
gpointer g_try_malloc (gsize n_bytes) G_GNUC_MALLOC G_GNUC_ALLOC_SIZE(1);
+GLIB_AVAILABLE_IN_ALL
gpointer g_try_malloc0 (gsize n_bytes) G_GNUC_MALLOC G_GNUC_ALLOC_SIZE(1);
+GLIB_AVAILABLE_IN_ALL
gpointer g_try_realloc (gpointer mem,
gsize n_bytes) G_GNUC_WARN_UNUSED_RESULT;
+GLIB_AVAILABLE_IN_ALL
gpointer g_malloc_n (gsize n_blocks,
gsize n_block_bytes) G_GNUC_MALLOC G_GNUC_ALLOC_SIZE2(1,2);
+GLIB_AVAILABLE_IN_ALL
gpointer g_malloc0_n (gsize n_blocks,
gsize n_block_bytes) G_GNUC_MALLOC G_GNUC_ALLOC_SIZE2(1,2);
+GLIB_AVAILABLE_IN_ALL
gpointer g_realloc_n (gpointer mem,
gsize n_blocks,
gsize n_block_bytes) G_GNUC_WARN_UNUSED_RESULT;
+GLIB_AVAILABLE_IN_ALL
gpointer g_try_malloc_n (gsize n_blocks,
gsize n_block_bytes) G_GNUC_MALLOC G_GNUC_ALLOC_SIZE2(1,2);
+GLIB_AVAILABLE_IN_ALL
gpointer g_try_malloc0_n (gsize n_blocks,
gsize n_block_bytes) G_GNUC_MALLOC G_GNUC_ALLOC_SIZE2(1,2);
+GLIB_AVAILABLE_IN_ALL
gpointer g_try_realloc_n (gpointer mem,
gsize n_blocks,
gsize n_block_bytes) G_GNUC_WARN_UNUSED_RESULT;
+#define g_clear_pointer(pp, destroy) \
+ G_STMT_START { \
+ G_STATIC_ASSERT (sizeof *(pp) == sizeof (gpointer)); \
+ /* Only one access, please */ \
+ gpointer *_pp = (gpointer *) (pp); \
+ gpointer _p; \
+ /* This assignment is needed to avoid a gcc warning */ \
+ GDestroyNotify _destroy = (GDestroyNotify) (destroy); \
+ \
+ (void) (0 ? (gpointer) *(pp) : 0); \
+ do \
+ _p = g_atomic_pointer_get (_pp); \
+ while G_UNLIKELY (!g_atomic_pointer_compare_and_exchange (_pp, _p, NULL)); \
+ \
+ if (_p) \
+ _destroy (_p); \
+ } G_STMT_END
/* Optimise: avoid the call to the (slower) _n function if we can
* determine at compile-time that no overflow happens.
gpointer (*try_realloc) (gpointer mem,
gsize n_bytes);
};
+GLIB_AVAILABLE_IN_ALL
void g_mem_set_vtable (GMemVTable *vtable);
+GLIB_AVAILABLE_IN_ALL
gboolean g_mem_is_system_malloc (void);
GLIB_VAR gboolean g_mem_gc_friendly;
/* Memory profiler and checker, has to be enabled via g_mem_set_vtable()
*/
GLIB_VAR GMemVTable *glib_mem_profiler_table;
+GLIB_AVAILABLE_IN_ALL
void g_mem_profile (void);
-
-/* deprecated memchunks and allocators */
-#if !defined (G_DISABLE_DEPRECATED) || defined (GTK_COMPILATION) || defined (GDK_COMPILATION)
-typedef struct _GAllocator GAllocator;
-typedef struct _GMemChunk GMemChunk;
-#define g_mem_chunk_create(type, pre_alloc, alloc_type) ( \
- g_mem_chunk_new (#type " mem chunks (" #pre_alloc ")", \
- sizeof (type), \
- sizeof (type) * (pre_alloc), \
- (alloc_type)) \
-)
-#define g_chunk_new(type, chunk) ( \
- (type *) g_mem_chunk_alloc (chunk) \
-)
-#define g_chunk_new0(type, chunk) ( \
- (type *) g_mem_chunk_alloc0 (chunk) \
-)
-#define g_chunk_free(mem, mem_chunk) G_STMT_START { \
- g_mem_chunk_free ((mem_chunk), (mem)); \
-} G_STMT_END
-#define G_ALLOC_ONLY 1
-#define G_ALLOC_AND_FREE 2
-GMemChunk* g_mem_chunk_new (const gchar *name,
- gint atom_size,
- gsize area_size,
- gint type);
-void g_mem_chunk_destroy (GMemChunk *mem_chunk);
-gpointer g_mem_chunk_alloc (GMemChunk *mem_chunk);
-gpointer g_mem_chunk_alloc0 (GMemChunk *mem_chunk);
-void g_mem_chunk_free (GMemChunk *mem_chunk,
- gpointer mem);
-void g_mem_chunk_clean (GMemChunk *mem_chunk);
-void g_mem_chunk_reset (GMemChunk *mem_chunk);
-void g_mem_chunk_print (GMemChunk *mem_chunk);
-void g_mem_chunk_info (void);
-void g_blow_chunks (void);
-GAllocator*g_allocator_new (const gchar *name,
- guint n_preallocs);
-void g_allocator_free (GAllocator *allocator);
-#define G_ALLOCATOR_LIST (1)
-#define G_ALLOCATOR_SLIST (2)
-#define G_ALLOCATOR_NODE (3)
-#endif /* G_DISABLE_DEPRECATED */
-
G_END_DECLS
#endif /* __G_MEM_H__ */