Quark
Object Hierarchy:
Description:
A GQuark is a non-zero integer which uniquely identifies a particular string.
A GQuark value of zero is associated to `NULL`.
Given either the string or the `GQuark` identifier it is possible to retrieve the other.
Quarks are used for both [datasets and keyed data lists](datalist-and-dataset.html).
To create a new quark from a string, use [func@GLib.quark_from_string] or [func@GLib.quark_from_static_string].
To find the string corresponding to a given `GQuark`, use [func@GLib.quark_to_string].
To find the `GQuark` corresponding to a given string, use [func@GLib.quark_try_string].
Another use for the string pool maintained for the quark functions is string interning, using [func@GLib.intern_string] or [ func@GLib.intern_static_string]. An interned string is a canonical representation for a string. One important advantage of interned strings is that they can be compared for equality by a simple pointer comparison, rather than using `strcmp()`.
Example: Quarks:
public static int main (string[] args) {
// ** from_string:
// Register a new string: Output: ``51``
Quark q = Quark.from_string ("my-test-str-1");
print ("my-test-str: %u\n", q);
// Get the registered quark: Output: ``51``
q = Quark.from_string ("my-test-str-1");
print ("my-test-str: %u\n", q);
// ** try_string:
// Known string: Output: ``51``
q = Quark.try_string ("my-test-str-1");
print ("my-test-str: %u\n", q);
// Unknown string: Output: ``0``
q = Quark.try_string ("my-test-str-UNKNOWN");
print ("my-test-str: %u\n", q);
return 0;
}
valac --pkg glib-2.0 GLib.Quark.vala