Home

gvalue

GValue is a generic value container in the GLib/GObject type system. It is designed to hold a value of any type registered in the GType system, enabling generic property access, signal marshalling, and value passing in a type-safe way. GValue is commonly used by the GObject property system and related APIs, and it provides a uniform mechanism to store, copy, and transfer values of diverse types.

A GValue must be initialized with a specific GType using g_value_init, which establishes the type of value

GValue supports a variety of GTypes, including primitive types, strings, pointers, objects, and boxed types. Some

In practice, GValue is most relevant for interacting with GObject properties, signal marshalling, and wrappers that

that
the
container
will
hold.
Once
initialized,
values
can
be
set
and
retrieved
with
type-specific
functions
such
as
g_value_set_int,
g_value_get_int,
g_value_set_string,
and
g_value_get_string.
There
are
corresponding
“take”
and
“copy”
operations
to
manage
ownership
and
lifetime
of
stored
data,
for
example
g_value_copy
duplicates
a
value
and
g_value_unset
frees
resources
held
by
the
container.
The
type
safety
of
operations
is
enforced
at
runtime;
attempting
to
set
a
value
with
an
incompatible
type
can
trigger
warnings
or
errors.
stored
values
require
special
memory
handling,
so
developers
should
use
the
appropriate
take
or
free
functions
as
documented
for
each
type.
The
lifecycle
of
a
GValue
typically
involves
initialization,
optional
set/get
operations,
copying
when
needed,
and
unsetting
to
release
resources.
need
to
abstract
over
multiple
possible
types.
For
newer
code
emphasizing
modern
data
interchange,
GLib
also
provides
other
mechanisms
such
as
GVariant,
but
GValue
remains
a
core,
compatible
facility
within
the
GLib
ecosystem.