Package: glib
GBoxed g-bytes
Superclasses
common-lisp:standard-object, common-lisp:t
Documented Subclasses
None
Direct Slots
None
Details
A simple refcounted data type representing an immutable sequence of zero or
more bytes from an unspecified origin.
The purpose of a g-bytes instance 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 g-bytes instance without coordinating their activities, resting assured that the byte data will not change or move while they hold a reference.
A g-bytes instance can come from many different origins that may have different procedures for freeing the memory region. Examples are memory from the g-malloc function. Usage of a g-bytes instance for a Lisp string as byte data.
The purpose of a g-bytes instance 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 g-bytes instance without coordinating their activities, resting assured that the byte data will not change or move while they hold a reference.
A g-bytes instance can come from many different origins that may have different procedures for freeing the memory region. Examples are memory from the g-malloc function.
Example
(multiple-value-bind (data len) (foreign-string-alloc "A test string.") (defvar bytes (g-bytes-new data len))) => BYTES (g-bytes-size bytes) => 15 (g-bytes-data bytes) => #.(SB-SYS:INT-SAP #X55EBB2C1DB70) => 15 (foreign-string-to-lisp (g-bytes-data bytes)) => "A test string." => 14
2021-12-10