Supplementary libraries: GDK, GLIB

GDK is the "Graphics Drawing Kit", and provides the low-level functionality that GTK uses in drawing objects to the screen. It can be used by a GTK+ application for pixel-level drawing and provides access to the Events that GTK+ uses in generating signals, allowing the programmer to determine which key or mouse button was pressed, for example.

GLIB may be thought of as an alteration of the standard C libraries, designed to allow for superior portability between different machine architectures and operating systems. For instance, instead of the standard C types: int, char, etc., GLIB offers the replacement data types gint, gchar and so on, as well as some useful new types such as gboolean, replacing the use of 0 or 1 as the true or false indicators in a conditional expression, or gpointer to replace void * as the generic operator type.

GLIB also offers a number of new structures and functions, including the GString data type and associated functions, which allows for the definition of character strings without having to think explicitly about memory allocation, which is performed automatically by the GString functions. For example

gStr = g_string_new("This is a string.");
creates a new GString object. The string may be reassigned a new value using
g_string_assign(gStr,"This is a different string.");
which handles the reallocation of memory itself. A GString object is freed using the command
g_string_free(gStr, TRUE);
The "TRUE" argument here ensures that the memory allocated to the string is completely freed.

GLIB similarly provides functions for setting up linked lists, both singly-linked and double-linked, hash tables and trees.

GLIB offers a degree of error message handling through the functions g_error, g_warning, g_message and g_print. g_error displays a formatted message and exits, g_warning and g_message display a formatted message indicating the type of message, but do not exit. g_print is essentially a replacement for printf, useful for debugging.

Previous: Compiling GTK+ Applications
Next: Links and Further Reading
Back to index