/** * g_malloc: * @n_bytes: the number of bytes to allocate * * Allocates @n_bytes bytes of memory. * If @n_bytes is 0 it returns %NULL. * * Returns: a pointer to the allocated memory */ gpointer g_malloc (gsize n_bytes) { if (G_LIKELY (n_bytes)) { gpointer mem; mem = malloc (n_bytes); TRACE (GLIB_MEM_ALLOC((void*) mem, (unsigned int) n_bytes, 0, 0)); if (mem) return mem; g_error ("%s: failed to allocate %"G_GSIZE_FORMAT" bytes", G_STRLOC, n_bytes); } TRACE(GLIB_MEM_ALLOC((void*) NULL, (int) n_bytes, 0, 0)); return NULL; }
/** * g_malloc0: * @n_bytes: the number of bytes to allocate * * Allocates @n_bytes bytes of memory, initialized to 0's. * If @n_bytes is 0 it returns %NULL. * * Returns: a pointer to the allocated memory */ gpointer g_malloc0 (gsize n_bytes) { if (G_UNLIKELY (!g_mem_initialized)) g_mem_init_nomessage(); if (G_LIKELY (n_bytes)) { gpointer mem; mem = glib_mem_vtable.calloc (1, n_bytes); TRACE (GLIB_MEM_ALLOC((void*) mem, (unsigned int) n_bytes, 1, 0)); if (mem) return mem; g_error ("%s: failed to allocate %"G_GSIZE_FORMAT" bytes", G_STRLOC, n_bytes); } TRACE(GLIB_MEM_ALLOC((void*) NULL, (int) n_bytes, 1, 0)); return NULL; }
/** * g_try_malloc: * @n_bytes: number of bytes to allocate. * * Attempts to allocate @n_bytes, and returns %NULL on failure. * Contrast with g_malloc(), which aborts the program on failure. * * Returns: the allocated memory, or %NULL. */ gpointer g_try_malloc (gsize n_bytes) { gpointer mem; if (G_LIKELY (n_bytes)) mem = malloc (n_bytes); else mem = NULL; TRACE (GLIB_MEM_ALLOC((void*) mem, (unsigned int) n_bytes, 0, 1)); return mem; }
/** * g_try_malloc: * @n_bytes: number of bytes to allocate. * * Attempts to allocate @n_bytes, and returns %NULL on failure. * Contrast with g_malloc(), which aborts the program on failure. * * Returns: the allocated memory, or %NULL. */ gpointer g_try_malloc (gsize n_bytes) { gpointer mem; if (G_UNLIKELY (!g_mem_initialized)) g_mem_init_nomessage(); if (G_LIKELY (n_bytes)) mem = glib_mem_vtable.try_malloc (n_bytes); else mem = NULL; TRACE (GLIB_MEM_ALLOC((void*) mem, (unsigned int) n_bytes, 0, 1)); return mem; }