At the most basic level of the GObject framework lies a generic and dynamic
type system called GType. The GType system holds a runtime description of all objects allowing
glue code to facilitate multiple language bindings. The type system can handle any
singly inherited class structure, in addition to
non-classed types such as
opaque pointers,
strings, and variously sized
integers and
floating point numbers. The type system knows how to copy, assign, and destroy values belonging to any of the registered types. This is trivial for types like integers, but many complex objects are
reference-counted, while some are complex but not reference-counted. When the type system "copies" a reference-counted object, it will typically just increase its reference count, whereas when copying a complex, non-reference-counted object (such as a string), it will typically create an actual copy by
allocating memory. This basic functionality is used for implementing GValue, a type of generic container that can hold values of any type known by the type system. Such containers are particularly useful when interacting with dynamically typed language environments in which all native values reside in such
type-tagged containers.
Fundamental types Types that do not have any associated
classes are called
non-classed. These types, together with all types that correspond to some form of root class, are known as
fundamental types: the types from which all other types are derived. These make up a relatively closed set, but although the average user is not expected to create their own fundamental types, the possibility does exist and has been exploited to create custom
class hierarchies — i.e., class hierarchies not based on the GObject class. As of GLib 2.9.2, the
non-classed built-in fundamental types are: • an
empty type, corresponding to C's void (G_TYPE_NONE); • types corresponding to C's signed and unsigned char, int, long, and 64-bit integers (G_TYPE_CHAR, G_TYPE_UCHAR, G_TYPE_INT, G_TYPE_UINT, G_TYPE_LONG, G_TYPE_ULONG, G_TYPE_INT64, and G_TYPE_UINT64); • a Boolean type (G_TYPE_BOOLEAN); • an
enumeration type and a "flags" type, both corresponding to C's enum type, but differing in that the latter is only used for
bit fields (G_TYPE_ENUM and G_TYPE_FLAGS); • types for single- and double-precision
IEEE floats, corresponding to C's float and double (G_TYPE_FLOAT and G_TYPE_DOUBLE); • a
string type, corresponding to C's char * (G_TYPE_STRING); • an opaque
pointer type, corresponding to C's void * (G_TYPE_POINTER). The
classed built-in fundamental types are: • a base class type for instances of GObject, the root of the standard class inheritance tree (G_TYPE_OBJECT) • a base
interface type, analogous to the base class type but representing the root of the standard
interface inheritance tree (G_TYPE_INTERFACE) • a type for
boxed structures, which are used to wrap simple value objects or foreign objects in reference-counted "boxes" (G_TYPE_BOXED) • a type for "parameter specification objects," which are used in GObject to describe
metadata for object properties (G_TYPE_PARAM). Types that can be instantiated automatically by the type system are called
instantiable. An important characteristic of these types is that the first bytes of any instance always contain a pointer to the
class structure (a form of
virtual table) associated to the type of the instance. For this reason, any instantiable type must be classed. Contrapositively, any non-classed type (such as
integer or
string) must be non-instantiable. On the other hand, most classed types are instantiable, but some, such as interface types, are not.
Derived types The types that are derived from the built-in GObject fundamental types fall roughly into four categories: ; Enumerated types and "flags" types : In general, every enumerated type and every integer-based bit field type (i.e., every enum type) that one wishes to use in some way that is related to the object system — for example, as the type of an object property — should be registered with the type system. Typically, the initialization code that takes care of registering these types is generated by an automated tool called glib-mkenums and stored in a separate file. ; Boxed types : Some data structures that are too simple to be made full-fledged class types (with all the overhead incurred) may still need to be registered with the type system. For example, we might have a class to which we want to add a background-color property, whose values should be instances of a structure that looks like {{code|2=c|1=struct color { int r, g, b; } }}. To avoid having to subclass GObject, we can create a
boxed type to represent this structure, and provide functions for copying and freeing. GObject ships with a handful of boxed types wrapping simple GLib data types. Another use for boxed types is as a way to wrap foreign objects in a tagged container that the type system can identify and will know how to copy and free. ; Opaque pointer types : Sometimes, for objects that need to be neither copied or reference-counted nor freed, even a boxed type would be overkill. While such objects can be used in GObject by simply treating them as opaque pointers (G_TYPE_POINTER), it is often a good idea to create a derived pointer type, documenting the fact that the pointers should reference a particular kind of object, even though nothing else is said about it. ; Class and interface types : Most types in a GObject application will be classes — in the normal object-oriented sense of the word — derived directly or indirectly from the root class, GObject. There are also interfaces, which, unlike classic
Java-style
interfaces, can contain implemented methods. GObject interfaces can thus be described as
mixins. ==Messaging system==