2014年02月11日 星期二 09:07
Quarks是一种并不常见的数据结构,至少我在开发过程中没有接触过。我是在学习GLib的过程中才看到的。按照官方文档的说法:
Quarks — a 2-way association between a string and a unique integer identifier.
Quarks are associations between strings and integer identifiers. Given either the string or the GQuark identifier it is possible to retrieve the other.
编程示例如下:
#include <stdio.h>
#include <glib.h>
#include <string.h>
#include <stdlib.h>
int main(int argc,char **argv) {
gchar *s=g_strdup("laozhang");
GQuark x=g_quark_from_string(s);
printf("quark of %s is %u\n",s,x);
printf("string of quark %u is %s\n",
x,g_quark_to_string(x));
const gchar *ss=g_intern_string(s);
printf("ss: %s\n",ss);
printf("address of ss: \t%p\n",ss);
printf("address quark: \t%p\n",
g_quark_to_string(x));
g_free(s);
s=g_strdup("laoli");
x=g_quark_from_string(s);
printf("quark of %s is %u\n",s,x);
printf("string of quark %u is %s\n",
x,g_quark_to_string(x));
return 0;
}
参考资料:
Zeuux © 2025
京ICP备05028076号