From b1d7a57cdf36a7a3ab0a9b3415aadaa21f16ee47 Mon Sep 17 00:00:00 2001 From: Nitin Wartkar Date: Mon, 7 Jun 2021 15:52:43 +0000 Subject: [PATCH] doc: example for GArray and g_array_set_clear_func() --- glib/garray.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/glib/garray.c b/glib/garray.c index 609a21038..025747ee5 100644 --- a/glib/garray.c +++ b/glib/garray.c @@ -299,6 +299,27 @@ g_array_sized_new (gboolean zero_terminated, * functions, @clear_func is expected to clear the contents of * the array element it is given, but not free the element itself. * + * |[ + * typedef struct + * { + * gchar *str; + * GObject *obj; + * } ArrayElement; + * + * static void + * array_element_clear (ArrayElement *element) + * { + * g_clear_pointer (&element->str, g_free); + * g_clear_object (&element->obj); + * } + * + * // main code + * GArray *garray = g_array_new (FALSE, FALSE, sizeof (ArrayElement)); + * g_array_set_clear_func (garray, (GDestroyNotify) array_element_clear); + * // assign data to the structure + * g_array_free (garray, TRUE); + * ]| + * * Since: 2.32 */ void