Object Hierarchy:

GLib.Bytes GLib.Bytes GLib.Bytes


[ Compact ]
[ Version ( since = "2.32" ) ]
[ CCode ( cprefix = "g_bytes_" , ref_function = "g_bytes_ref" , type_id = "G_TYPE_BYTES" , unref_function = "g_bytes_unref" ) ]
public class Bytes

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

The purpose of a Bytes 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 Bytes without coordinating their activities, resting assured that the byte data will not change or move while they hold a reference.

A Bytes can come from many different origins that may have different procedures for freeing the memory region. Examples are memory from malloc, from memory slices, from a MappedFile or memory from other allocators.

Bytes work well as keys in GenericSet. Use g_bytes_equal and hash as parameters to g_hash_table_new or GenericSet. Bytes can also be used as keys in a Tree by passing the compare function to g_tree_new.

The data pointed to by this bytes must not be modified. For a mutable array of bytes see ByteArray. Use unref_to_array to create a mutable array for a Bytes sequence. To create an immutable Bytes from a mutable ByteArray, use the free_to_bytes function.

Namespace: GLib
Package: glib-2.0



Static methods:

Creation methods: