Home

GSList

GSList is GLib's implementation of a generic singly linked list. It provides a simple, dynamically allocated chain of nodes where each node holds a pointer to data (gpointer) and a pointer to the next node. Because the data field is a void pointer, GSList can store pointers to any type, making it a flexible container for GTK and GLib-based projects.

Structure and usage: A GSList is a singly linked list, so insertion and removal at the head

Memory management: The list nodes themselves are allocated and freed by the GSList APIs. By default, freeing

Relation to other types: GSList is the singly linked list variant in GLib. Its counterpart is GList,

See also: GLib documentation for GSList and the related GList structure.

is
typically
constant
time,
while
operations
at
the
tail
or
in
the
middle
may
require
traversal.
The
core
API
offers
a
variety
of
constructors,
mutators,
and
accessors.
Common
operations
include
g_slist_prepend
to
add
an
element
at
the
front,
g_slist_append
to
add
to
the
end,
and
g_slist_insert
to
place
an
element
at
a
specified
position.
Other
utilities
cover
removal
(g_slist_remove,
g_slist_remove_all),
access
(g_slist_nth,
g_slist_nth_data,
g_slist_last),
queries
(g_slist_length),
and
common
transformations
such
as
g_slist_reverse,
g_slist_concat,
and
g_slist_sort
(with
an
optional
variant
for
data-dependent
sorting).
a
list
with
g_slist_free
releases
only
the
nodes;
the
data
pointed
to
by
each
node
is
not
freed
automatically,
so
the
caller
must
manage
that
memory
or
use
an
appropriate
destroy
function
when
freeing
the
elements
(in
supported
GLib
versions,
a
full/free_with-data
variant
may
be
available).
which
implements
a
doubly
linked
list.
Both
types
are
widely
used
in
GLib
and
GTK
applications,
offering
different
trade-offs
for
insertion,
deletion,
and
traversal.