1 <!-- ##### SECTION Title ##### -->
4 <!-- ##### SECTION Short_Description ##### -->
5 arrays of bytes, which grow automatically as elements are added.
7 <!-- ##### SECTION Long_Description ##### -->
9 GByteArray is based on #GArray, to provide arrays of bytes which grow
10 automatically as elements are added.
13 To create a new #GByteArray use g_byte_array_new().
16 To add elements to a #GByteArray, use g_byte_array_append(), and
17 g_byte_array_prepend().
20 To set the size of a GByteArray, use g_byte_array_set_size().
23 To free a GByteArray, use g_byte_array_free().
27 <title>Using a GByteArray.</title>
32 gbarray = g_byte_array_new ();
33 for (i = 0; i < 10000; i++)
34 g_byte_array_append (gbarray, (guint8*) "abcd", 4);
36 for (i = 0; i < 10000; i++)
38 g_assert (gbarray->data[4*i] == 'a');
39 g_assert (gbarray->data[4*i+1] == 'b');
40 g_assert (gbarray->data[4*i+2] == 'c');
41 g_assert (gbarray->data[4*i+3] == 'd');
44 g_byte_array_free (gbarray, TRUE);
45 </programlisting></example>
47 <!-- ##### SECTION See_Also ##### -->
52 <!-- ##### STRUCT GByteArray ##### -->
54 The #GByteArray struct allows access to the public fields of a #GByteArray.
57 @data: a pointer to the element data. The data may be moved as elements are
58 added to the #GByteArray.
59 @len: the number of elements in the #GByteArray.
61 <!-- ##### FUNCTION g_byte_array_new ##### -->
63 Creates a new #GByteArray.
66 @Returns: the new #GByteArray.
69 <!-- ##### FUNCTION g_byte_array_sized_new ##### -->
78 <!-- ##### FUNCTION g_byte_array_append ##### -->
80 Adds the given bytes to the end of the #GByteArray.
81 The array will grow in size automatically if necessary.
84 @array: a #GByteArray.
85 @data: the byte data to be added.
86 @len: the number of bytes to add.
87 @Returns: the #GByteArray.
90 <!-- ##### FUNCTION g_byte_array_prepend ##### -->
92 Adds the given data to the start of the #GByteArray.
93 The array will grow in size automatically if necessary.
96 @array: a #GByteArray.
97 @data: the byte data to be added.
98 @len: the number of bytes to add.
99 @Returns: the #GByteArray.
102 <!-- ##### FUNCTION g_byte_array_remove_index ##### -->
104 Removes the byte at the given index from a #GByteArray.
105 The following bytes are moved down one place.
108 @array: a #GByteArray.
109 @index: the index of the byte to remove.
110 @Returns: the #GByteArray.
113 <!-- ##### FUNCTION g_byte_array_remove_index_fast ##### -->
115 Removes the byte at the given index from a #GByteArray.
116 The last element in the array is used to fill in the space, so this function
117 does not preserve the order of the #GByteArray. But it is faster than
118 g_byte_array_remove_index().
121 @array: a #GByteArray.
122 @index: the index of the byte to remove.
123 @Returns: the #GByteArray.
126 <!-- ##### FUNCTION g_byte_array_set_size ##### -->
128 Sets the size of the #GByteArray, expanding it if necessary.
131 @array: a #GByteArray.
132 @length: the new size of the #GByteArray.
133 @Returns: the #GByteArray.
136 <!-- ##### FUNCTION g_byte_array_free ##### -->
138 Frees the memory allocated by the #GByteArray.
139 If free_segment is TRUE it frees the actual byte data.
142 @array: a #GByteArray.
143 @free_segment: if TRUE the actual byte data is freed as well.