The GType API is the foundation of the GObject system. It provides the facilities for registering and managing all fundamental data types, user-defined object and interface types.
For type creation and registration purposes, all types fall into one of
two categories: static or dynamic. Static types are never loaded or
unloaded at run-time as dynamic types may be. Static types are created
g_type_register_static() that gets type specific
information passed in via a
Dynamic types are created with
which takes a
GTypePlugin structure instead. The remaining type information
GTypeInfo structure) is retrieved during runtime through
These registration functions are usually called only once from a function whose only purpose is to return the type identifier for a specific class. Once the type (or class or interface) is registered, it may be instantiated, inherited, or implemented depending on exactly what sort of type it is.
There is also a third registration function for registering fundamental
g_type_register_fundamental(), which requires
GTypeInfo structure and a
GTypeFundamentalInfo structure, but it
is rarely used since most fundamental types are predefined rather than user-defined.
Type instance and class structs are limited to a total of 64 KiB,
including all parent types. Similarly, type instances’ private data
(as created by
G_ADD_PRIVATE()) are limited to a total of
64 KiB. If a type instance needs a large static buffer, allocate it
separately (typically by using
and put a pointer to the buffer in the structure.
As mentioned in the GType conventions, type names must be at least three characters long. There is no upper length limit. The first character must be a letter (a–z or A–Z) or an underscore (‘_’). Subsequent characters can be letters, numbers or any of ‘-_+’.
G_ENABLE_DEBUG is defined during compilation, the GObject library
supports an environment variable
GOBJECT_DEBUG that can be set to a
combination of flags to trigger debugging messages about
object bookkeeping and signal emissions during runtime.
The currently supported flags are:
objects: Tracks all
GObjectinstances in a global hash table called
debug_objects_ht, and prints the still-alive objects on exit.
instance-count: Tracks the number of instances of every
GTypeand makes it available via the
signals: Currently unused.