GLib.VariantBuilder.init

### Method

# GLib VariantBuilderinit

since: 2.24

#### Declaration [src]

    void
    g_variant_builder_init (
      GVariantBuilder* builder,
      const GVariantType* type
    )

#### Description [src]

Initialises a `GVariantBuilder` structure.

`type` must be non-`NULL`. It specifies the type of container to construct. It can be an indefinite type such as `G_VARIANT_TYPE_ARRAY` or a definite type such as “as” or “(ii)”. Maybe, array, tuple, dictionary entry and variant-typed values may be constructed.

If using a static type such as one of the `G_VARIANT_TYPE_*` constants or a `G_VARIANT_TYPE ("(ii)")` macro, it is more performant to use `g_variant_builder_init_static()` rather than g_variant_builder_init().

After the builder is initialised, values are added using `g_variant_builder_add_value()` or g_variant_builder_add().

After all the child values are added, `g_variant_builder_end()` frees the memory associated with the builder and returns the `GVariant` that was created.

This function completely ignores the previous contents of `builder`. On one hand this means that it is valid to pass in completely uninitialised memory. On the other hand, this means that if you are initialising over top of an existing `GVariantBuilder` you need to first call `g_variant_builder_clear()` in order to avoid leaking memory.

You must not call `g_variant_builder_ref()` or `g_variant_builder_unref()` on a `GVariantBuilder` that was initialised with this function. If you ever pass a reference to a `GVariantBuilder` outside of the control of your own code then you should assume that the person receiving that reference may try to use reference counting; you should use `g_variant_builder_new()` instead of this function.

Available since: 2.24

This method is not directly available to language bindings.

#### Parameters

`type`

  Type: `GVariantType`

  A container type.

  The data is owned by the caller of the method.