Bytes

A simple refcounted 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 glib.global.gmalloc, from memory slices, from a #GMappedFile or memory from other allocators.

#GBytes work well as keys in #GHashTable. Use glib.bytes.Bytes.equal and glib.bytes.Bytes.hash as parameters to glib.hash_table.HashTable.new_ or glib.hash_table.HashTable.newFull. #GBytes can also be used as keys in a #GTree by passing the glib.bytes.Bytes.compare function to glib.tree.Tree.new_.

The data pointed to by this bytes must not be modified. For a mutable array of bytes see #GByteArray. Use glib.bytes.Bytes.unrefToArray to create a mutable array for a #GBytes sequence. To create an immutable #GBytes from a mutable #GByteArray, use the glib.byte_array.ByteArray.freeToBytes function.

Constructors

this
this(ubyte[] data)

Creates a new #GBytes from data.

Members

Functions

compare
int compare(glib.bytes.Bytes bytes2)

Compares the two #GBytes values.

equal
bool equal(glib.bytes.Bytes bytes2)

Compares the two #GBytes values being pointed to and returns true if they are equal.

getData
ubyte[] getData()

Get the byte data in the #GBytes. This data should not be modified.

getRegion
const(void)* getRegion(size_t elementSize, size_t offset, size_t nElements)

Gets a pointer to a region in bytes.

getSize
size_t getSize()

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

hash
uint hash()

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

newFromBytes
glib.bytes.Bytes newFromBytes(size_t offset, size_t length)

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

unrefToArray
ubyte[] unrefToArray()

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

unrefToData
ubyte[] unrefToData()

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

Inherited Members

From Boxed

cInstancePtr
void* cInstancePtr;

Pointer to the C boxed value

getType
GType getType()

Get the GType of this boxed type.

gType
GType gType [@property getter]

Boxed GType property.

self
Boxed self()

Convenience method to return this cast to a type. For use in D with statements.

copy_
void* copy_()

Make a copy of the wrapped C boxed data.

boxedCopy
void* boxedCopy(void* cBoxed)

Copy a C boxed value using g_boxed_copy.

boxedFree
void boxedFree(void* cBoxed)

Free a C boxed value using g_boxed_free.