GLib.Bytes
Description: Reference for GLib.Bytes

### Struct

# GLibBytes

since: 2.32

#### Description [src]

    struct GBytes {
      /* No available fields */
    }

A simple reference counted data type representing an immutable sequence of zero or more bytes from an unspecified origin.

The purpose of a `GBytes` is to keep the memory region that it holds alive for as long as anyone holds a reference to the bytes. When the last reference count is dropped, the memory is released. Multiple unrelated callers can use byte data in the `GBytes` without coordinating their activities, resting assured that the byte data will not change or move while they hold a reference.

A `GBytes` can come from many different origins that may have different procedures for freeing the memory region. Examples are memory from `g_malloc()`, from memory slices, from a `GMappedFile` or memory from other allocators.

`GBytes` work well as keys in `GHashTable`. Use `g_bytes_equal()` and `g_bytes_hash()` as parameters to `g_hash_table_new()` or `g_hash_table_new_full()`. `GBytes` can also be used as keys in a `GTree` by passing the `g_bytes_compare()` function to `g_tree_new()`.

The data pointed to by this bytes must not be modified. For a mutable array of bytes see `GByteArray`. Use `g_bytes_unref_to_array()` to create a mutable array for a `GBytes` sequence. To create an immutable `GBytes` from a mutable `GByteArray`, use the `g_byte_array_free_to_bytes()` function.

Available since: 2.32

#### Constructors

###### g_bytes_new

Creates a new `GBytes` from `data`.

since: 2.32

###### g_bytes_new_from_bytes

Creates a `GBytes` which is a subsection of another `GBytes`.

since: 2.32

###### g_bytes_new_static

Creates a new `GBytes` from static data.

since: 2.32

###### g_bytes_new_take

Creates a new `GBytes` from `data`.

since: 2.32

###### g_bytes_new_with_free_func

Creates a `GBytes` from `data`.

since: 2.32

#### Instance methods

###### g_bytes_compare

Compares the two `GBytes` values.

since: 2.32

###### g_bytes_equal

Compares the two `GBytes` values being pointed to and returns `TRUE` if they are equal.

since: 2.32

###### g_bytes_get_data

Get the byte data in the `GBytes`.

since: 2.32

###### g_bytes_get_region

Gets a pointer to a region in `bytes`.

since: 2.70

###### g_bytes_get_size

Get the size of the byte data in the `GBytes`.

since: 2.32

###### g_bytes_hash

Creates an integer hash code for the byte data in the `GBytes`.

since: 2.32

###### g_bytes_ref

Increase the reference count on `bytes`.

since: 2.32

###### g_bytes_unref

Releases a reference on `bytes`.

since: 2.32

###### g_bytes_unref_to_array

Unreferences the bytes, and returns a new mutable `GByteArray` containing the same byte data.

since: 2.32

###### g_bytes_unref_to_data

Unreferences the bytes, and returns a pointer the same byte data contents.

since: 2.32