Function Macro

GLibPRIVATE_INIT

since: 2.32

Declaration

#define G_PRIVATE_INIT (
  notify
)

Description

A macro to assist with the static initialisation of a GPrivate.

This macro is useful for the case that a GDestroyNotify function should be associated with the key. This is needed when the key will be used to point at memory that should be deallocated when the thread exits.

Additionally, the GDestroyNotify will also be called on the previous value stored in the key when g_private_replace() is used.

If no GDestroyNotify is needed, then use of this macro is not required — if the GPrivate is declared in static scope then it will be properly initialised by default (ie: to all zeros). See the examples below.

static GPrivate name_key = G_PRIVATE_INIT (g_free);

// return value should not be freed
const gchar *
get_local_name (void)
{
  return g_private_get (&name_key);
}

void
set_local_name (const gchar *name)
{
  g_private_replace (&name_key, g_strdup (name));
}


static GPrivate count_key;   // no free function

gint
get_local_count (void)
{
  return GPOINTER_TO_INT (g_private_get (&count_key));
}

void
set_local_count (gint count)
{
  g_private_set (&count_key, GINT_TO_POINTER (count));
}

Available since: 2.32

This function is not directly available to language bindings.

Parameters

notify

Type: -

A GDestroyNotify.