<!-- ##### SECTION Title ##### -->
Byte Arrays

<!-- ##### SECTION Short_Description ##### -->
arrays of bytes, which grow automatically as elements are added.

<!-- ##### SECTION Long_Description ##### -->
<para>
GByteArray is based on #GArray, to provide arrays of bytes which grow
automatically as elements are added.
</para>
<para>
To create a new #GByteArray use g_byte_array_new().
</para>
<para>
To add elements to a #GByteArray, use g_byte_array_append(), and
g_byte_array_prepend().
</para>
<para>
To set the size of a GByteArray, use g_byte_array_set_size().
</para>
<para>
To free a GByteArray, use g_byte_array_free().
</para>

<example>
<title>Using a GByteArray.</title>
<programlisting>
  GByteArray *gbarray;
  gint i;

  gbarray = g_byte_array_new ();
  for (i = 0; i < 10000; i++)
    g_byte_array_append (gbarray, (guint8*) "abcd", 4);

  for (i = 0; i < 10000; i++)
    {
      g_assert (gbarray->data[4*i] == 'a');
      g_assert (gbarray->data[4*i+1] == 'b');
      g_assert (gbarray->data[4*i+2] == 'c');
      g_assert (gbarray->data[4*i+3] == 'd');
    }

  g_byte_array_free (gbarray, TRUE);
</programlisting></example>

<!-- ##### STRUCT GByteArray ##### -->
<para>
The GByteArray struct allows access to the public fields of a GByteArray.
The <structfield>data</structfield> field points to the element data.
It may change as elements are added to the array.
The <structfield>len</structfield> field contains the number of elements
in the array.
</para>


<!-- ##### FUNCTION g_byte_array_new ##### -->
<para>
Creates a new #GByteArray.
</para>

@Returns: the new #GByteArray.

<!-- ##### FUNCTION g_byte_array_append ##### -->
<para>
Adds the given bytes to the end of the #GByteArray.
The array will grow in size automatically if necessary.
</para>

@array: a #GByteArray.
@data: the byte data to be added.
@len: the number of bytes to add.
@Returns: the #GByteArray.

<!-- ##### FUNCTION g_byte_array_prepend ##### -->
<para>
Adds the given data to the start of the #GByteArray.
The array will grow in size automatically if necessary.
</para>

@array: a #GByteArray.
@data: the byte data to be added.
@len: the number of bytes to add.
@Returns: the #GByteArray.

<!-- ##### FUNCTION g_byte_array_set_size ##### -->
<para>
Sets the size of the #GByteArray, expanding it if necessary.
</para>

@array: a #GByteArray.
@length: the new size of the #GByteArray.
@Returns: the #GByteArray.

<!-- ##### FUNCTION g_byte_array_free ##### -->
<para>
Frees the memory allocated by the #GByteArray.
If free_segment is TRUE it frees the actual byte data.
</para>

@array: a #GByteArray.
@free_segment: if TRUE the actual byte data is freed as well.

