Home

GVariant

GVariant is a data type in the GLib core library designed to hold a value together with its type information. It is immutable once created and is used to simplify inter-process communication and data serialization. GVariant values are described by a type signature, a string notation that encodes primitive and container types, such as s for string, i for 32-bit integer, b for boolean, and container forms like a{sv} for a dictionary mapping strings to variants, and (si) for a two-element tuple.

Implementation revolves around a small runtime type system composed of GVariantType objects that describe the shape

GLib provides builders and iterators for working with complex values: GVariantBuilder constructs nested variants, and GVariantIter

GVariant is a central data container in GNOME software stacks because it enables robust, typed, and portable

of
a
value,
and
GVariant
values
themselves
that
store
the
data.
The
API
favors
efficiency
through
immutability
and
zero-copy
representations
where
possible,
and
it
uses
reference
counting
for
memory
management
via
appropriate
functions.
allows
streaming
access
to
elements
in
arrays
and
dictionaries.
Functions
exist
to
print
and
parse
textual
representations
as
well
as
to
integrate
with
D-Bus
(GDBus)
and
GSettings,
where
GVariant
is
the
standard
value
container.
data
exchange
between
processes
and
components.
Its
design
emphasizes
type-safety,
cross-process
compatibility,
and
efficient
memory
handling,
making
it
a
foundational
element
in
GLib-based
applications.