ByteArray

GByteArray is a mutable array of bytes based on GArray, to provide arrays of bytes which grow automatically as elements are added.

To create a new GByteArray use g_byte_array_new(). To add elements to a GByteArray, use g_byte_array_append(), and g_byte_array_prepend().

To set the size of a GByteArray, use g_byte_array_set_size().

To free a GByteArray, use g_byte_array_free().

See GBytes if you are interested in an immutable object representing a sequence of bytes.

Constructors

this
this(GByteArray* gByteArray)

Sets our main struct and passes it to the parent class

this
this()

Creates a new GByteArray with a reference count of 1.

this
this(ubyte[] data)

Create byte array containing the data. The data will be owned by the array and will be freed with g_free(), i.e. it could be allocated using g_strdup(). Since 2.32

Members

Functions

append
ByteArray append(ubyte[] data)

Adds the given bytes to the end of the GByteArray. The array will grow in size automatically if necessary.

doref
ByteArray doref()

Atomically increments the reference count of array by one. This function is MT-safe and may be called from any thread. Since 2.22

free
ubyte* free(int freeSegment)

Frees the memory allocated by the GByteArray. If free_segment is TRUE it frees the actual byte data. If the reference count of array is greater than one, the GByteArray wrapper is preserved but the size of array will be set to zero.

freeToBytes
Bytes freeToBytes()

Transfers the data from the GByteArray into a new immutable GBytes. The GByteArray is freed unless the reference count of array is greater than one, the GByteArray wrapper is preserved but the size of array will be set to zero. This is identical to using g_bytes_new_take() and g_byte_array_free() together. Since 2.32

getByteArrayStruct
GByteArray* getByteArrayStruct()
Undocumented in source. Be warned that the author may not have intended to support it.
getStruct
void* getStruct()

the main Gtk struct as a void*

prepend
ByteArray prepend(ubyte[] data)

Adds the given data to the start of the GByteArray. The array will grow in size automatically if necessary.

removeIndex
ByteArray removeIndex(uint index)

Removes the byte at the given index from a GByteArray. The following bytes are moved down one place.

removeIndexFast
ByteArray removeIndexFast(uint index)

Removes the byte at the given index from a GByteArray. The last element in the array is used to fill in the space, so this function does not preserve the order of the GByteArray. But it is faster than g_byte_array_remove_index().

removeRange
ByteArray removeRange(uint index, uint length)

Removes the given number of bytes starting at the given index from a GByteArray. The following elements are moved to close the gap. Since 2.4

setSize
ByteArray setSize(uint length)

Sets the size of the GByteArray, expanding it if necessary.

sort
void sort(GCompareFunc compareFunc)

Sorts a byte array, using compare_func which should be a qsort()-style comparison function (returns less than zero for first arg is less than second arg, zero for equal, greater than zero if first arg is greater than second arg). If two array elements compare equal, their order in the sorted array is undefined. If you want equal elements to keep their order (i.e. you want a stable sort) you can write a comparison function that, if two elements would otherwise compare equal, compares them by their addresses.

sortWithData
void sortWithData(GCompareDataFunc compareFunc, void* userData)

Like g_byte_array_sort(), but the comparison function takes an extra user data argument.

unref
void unref()

Atomically decrements the reference count of array by one. If the reference count drops to 0, all memory allocated by the array is released. This function is MT-safe and may be called from any thread. Since 2.22

Static functions

sizedNew
ByteArray sizedNew(uint reservedSize)

Creates a new GByteArray with reserved_size bytes preallocated. This avoids frequent reallocation, if you are going to add many bytes to the array. Note however that the size of the array is still 0.

Variables

gByteArray
GByteArray* gByteArray;

the main Gtk struct

Meta