Next: Generating type definitions by introspection, Previous: Creating GObjects classes and implementing GInterfaces, Up: Top
GObject manual defines this type in the following way:
“GBoxed is a generic wrapper mechanism for arbitrary C structures. The only thing the type system needs to know about the structures is how to copy and free them, beyond that they are treated as opaque chunks of memory.
Boxed types are useful for simple value-holder structures like rectangles or points. They can also be used for wrapping structures defined in non-GObject based libraries.”
Naturally, it is hard to provide support for “arbitrary C structures”. We support a few useful use cases of GBoxed types:
:include
defstruct
option).
For example, Gdk has structure GdkEvent which is a union of GdkEventAny, GdkEventExpose and other structures. These structures have common slots: “type”, “window”, “send_event”. By dispatching on “type”, user or GdkEvent structure knows which of GdkEvent* structures it has and can access other fields.