Why use g_print, g_malloc, g_strdup and fellow glib functions?

GTK+ FAQ
<<< Previous | About GLib | Next >>>

# Why use g_print, g_malloc, g_strdup and fellow glib functions?

Thanks to Tim Janik who wrote to gtk-list: (slightly modified)

"Regarding g_malloc(), g_free() and siblings, these functions are much safer than their libc equivalents. For example, g_free() just returns if called with NULL. Also, if USE_DMALLOC is defined, the definition for these functions changes (in glib.h) to use MALLOC(), FREE() etc... If MEM_PROFILE or MEM_CHECK are defined, there are even small statistics made counting the used block sizes (shown by g_mem_profile() / g_mem_check())."

"Considering the fact that glib provides an interface for memory chunks to save space if you have lots of blocks that are always the same size and to mark them ALLOC_ONLY if needed, it is just straight forward to create a small saver (debug able) wrapper around the normal malloc/free stuff as well - just like gdk covers Xlib. ;)"

"Using g_error() and g_warning() inside of applications like the GIMP that fully rely on gtk even gives the opportunity to pop up a window showing the messages inside of a gtk window with your own handler (by using g_set_error_handler()) along the lines of `gtk_print()` (inside of gtkmain.c)."

<<< Previous | Home | Next >>>
Memory does not seem to be released when I free the list nodes I've allocated | Up | What's a GScanner and how do I use one?