1.3 <GByteArray>

Structure: <GByteArray>

Contains the public fields of a <GByteArray>.

Fields

data

a pointer to the element data. The data may be moved as elements are added to the <GByteArray>

len

the number of elements in the <GByteArray>

Procedures

Procedure: byte-array:append array data ⇒ %return

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

array

Passed: a bytevector.

a byte array

data

Passed: a bytevector, or a list or vector, each an unsigned 8-bit integer.

the byte data to be added

%return

Returned: a bytevector.

The <GByteArray>

len

Not passed: guile-gi gives the length of data.

the number of bytes to add

Procedure: byte-array:free array free-segment ⇒ %return

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.

array

Passed: a bytevector.

a byte array

free-segment

Passed: a boolean.

if true, the actual byte data is freed as well

%return

Returned: a foreign pointer, or #f.

The allocated element data if free-segment is false, otherwise NULL.

Procedure: byte-array:free-to-bytes array ⇒ %return

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, in which the <GByteArray> wrapper is preserved but the size of array will be set to zero.

This is identical to using bytes:new-take and byte-array:free together.

array

Passed: a bytevector.

a byte array

%return

Returned: a <GBytes>.

The new immutable <GBytes> representing same byte data that was in the array

Procedure: byte-array:new ⇒ %return

Creates a new <GByteArray> with a reference count of 1.

%return

Returned: a bytevector.

The new <GByteArray>

Procedure: byte-array:new-take data ⇒ %return

Creates a byte array containing the data. After this call, data belongs to the <GByteArray> and may no longer be modified by the caller. The memory of data has to be dynamically allocated and will eventually be freed with byte-array:free.

Do not use it if len is greater than ‘G_MAXUINT‘. <GByteArray> stores the length of its data in guint, which may be shorter than gsize.

data

Passed: a bytevector, or a list or vector, each an unsigned 8-bit integer.

the byte data for the array

%return

Returned: a bytevector.

The new <GByteArray>

len

Not passed: guile-gi gives the length of data.

the length of data

Procedure: byte-array:prepend array data ⇒ %return

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

array

Passed: a bytevector.

a byte array

data

Passed: a bytevector, or a list or vector, each an unsigned 8-bit integer.

the byte data to be added

%return

Returned: a bytevector.

The <GByteArray>

len

Not passed: guile-gi gives the length of data.

the number of bytes to add

Procedure: byte-array:ref array ⇒ %return

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

array

Passed: a bytevector.

a byte array

%return

Returned: a bytevector.

The passed in <GByteArray>

Procedure: byte-array:remove-index array index- ⇒ %return

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

array

Passed: a bytevector.

a byte array

index-

Passed: an unsigned 32-bit integer.

the index of the byte to remove

%return

Returned: a bytevector.

The <GByteArray>

Procedure: byte-array:remove-index-fast array index- ⇒ %return

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 byte-array:remove-index.

array

Passed: a bytevector.

a byte array

index-

Passed: an unsigned 32-bit integer.

the index of the byte to remove

%return

Returned: a bytevector.

The <GByteArray>

Procedure: byte-array:remove-range array index- length ⇒ %return

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

array

Passed: a bytevector.

a byte array

index-

Passed: an unsigned 32-bit integer.

the index of the first byte to remove

length

Passed: an unsigned 32-bit integer.

the number of bytes to remove

%return

Returned: a bytevector.

The <GByteArray>

Procedure: byte-array:set-size array length ⇒ %return

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

array

Passed: a bytevector.

a byte array

length

Passed: an unsigned 32-bit integer.

the new size of the <GByteArray>

%return

Returned: a bytevector.

The <GByteArray>

Procedure: byte-array:sized-new reserved-size ⇒ %return

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.

reserved-size

Passed: an unsigned 32-bit integer.

the number of bytes preallocated

%return

Returned: a bytevector.

The new <GByteArray>

Procedure: byte-array:sort array compare-func

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.

array

Passed: a bytevector.

a byte array

compare-func

Passed: a procedure.

the comparison function

See GCompareFunc for how it is called.

Procedure: byte-array:sort-with-data array compare-func

Like byte-array:sort, but the comparison function takes an extra user data argument.

array

Passed: a bytevector.

a byte array

compare-func

Passed: a procedure.

the comparison function

See GCompareDataFunc for how it is called.

user-data

Not passed: guile-gi supplies it.

the data to pass to compare-func

Procedure: byte-array:steal array ⇒ %return

Frees the data in the array and resets the size to zero, while the underlying array is preserved for use elsewhere and returned to the caller.

array

Passed: a bytevector.

a byte array

%return

Returned: a bytevector.

The allocated element data

len

Not returned: it is the length of %return.

the pointer to retrieve the number of elements of the original array

Procedure: byte-array:unref array

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 thread-safe and may be called from any thread.

array

Passed: a bytevector.

a byte array