Bytes

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

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

A glib.Bytes 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 glib.MappedFile or memory from other allocators.

glib.Bytes work well as keys in glib.HashTable Use Bytes.equal and Bytes.hash as parameters to HashTable.new or HashTable.newFull. glib.Bytes can also be used as keys in a GTree by passing the 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 glib.ByteArray Use Bytes.unrefToArray to create a mutable array for a glib.Bytes sequence. To create an immutable glib.Bytes from a mutable glib.ByteArray, use the ByteArray.freeToBytes function.

Constructors

this
this(GBytes* gBytes, bool ownedRef)

Sets our main struct and passes it to the parent class.

this
this(ubyte[] data)

Creates a new glib.Bytes from data.

this
this(ubyte[] data, GDestroyNotify freeFunc, void* userData)

Creates a glib.Bytes from data.

Destructor

A destructor is present on this object, but not explicitly documented in the source.

Members

Functions

compare
int compare(Bytes bytes2)

Compares the two glib.Bytes values.

equal
bool equal(Bytes bytes2)

Compares the two glib.Bytes values being pointed to and returns TRUE if they are equal.

getBytesStruct
GBytes* getBytesStruct(bool transferOwnership)

Get the main Gtk struct

getData
ubyte[] getData()

Get the byte data in the glib.Bytes This data should not be modified.

getSize
size_t getSize()

Get the size of the byte data in the glib.Bytes

getStruct
void* getStruct()

the main Gtk struct as a void*

hash
uint hash()

Creates an integer hash code for the byte data in the glib.Bytes

newFromBytes
Bytes newFromBytes(size_t offset, size_t length)

Creates a glib.Bytes which is a subsection of another glib.Bytes The offset + length may not be longer than the size of bytes.

ref_
Bytes ref_()

Increase the reference count on bytes.

unref
void unref()

Releases a reference on bytes. This may result in the bytes being freed. If bytes is NULL, it will return immediately.

unrefToArray
ByteArray unrefToArray()

Unreferences the bytes, and returns a new mutable glib.ByteArray containing the same byte data.

unrefToData
ubyte[] unrefToData()

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

Variables

gBytes
GBytes* gBytes;

the main Gtk struct

Meta

Since

2.32