There are a bunch of fundamental types being registered in GLib’s GType subsystem (GLib’s source file gvaluetypes.c
follows):
/* --- type initialization --- */
void
_g_value_types_init (void)
{
GTypeInfo info = {
0, /* class_size */
NULL, /* base_init */
NULL, /* base_destroy */
NULL, /* class_init */
NULL, /* class_destroy */
NULL, /* class_data */
0, /* instance_size */
0, /* n_preallocs */
NULL, /* instance_init */
NULL, /* value_table */
};
const GTypeFundamentalInfo finfo = { G_TYPE_FLAG_DERIVABLE, };
GType type G_GNUC_UNUSED /* when compiling with G_DISABLE_ASSERT */;
/* G_TYPE_CHAR / G_TYPE_UCHAR
*/
{
static const GTypeValueTable value_table = {
value_init_long0, /* value_init */
NULL, /* value_free */
value_copy_long0, /* value_copy */
NULL, /* value_peek_pointer */
"i", /* collect_format */
value_collect_int, /* collect_value */
"p", /* lcopy_format */
value_lcopy_char, /* lcopy_value */
};
info.value_table = &value_table;
type = g_type_register_fundamental (G_TYPE_CHAR, g_intern_static_string ("gchar"), &info, &finfo, 0);
g_assert (type == G_TYPE_CHAR);
type = g_type_register_fundamental (G_TYPE_UCHAR, g_intern_static_string ("guchar"), &info, &finfo, 0);
g_assert (type == G_TYPE_UCHAR);
}
…
…
…
I wonder why instance_size
of info
struct isn’t being used? Don’t fundamental types have/use any “instance size”? I’m planning on using this subsystem to register a few types,
including fundamental ones, and I wonder if I should specify,
e.g.: 8
for instance_size
for a gint64
–equivalent type?
In general, what’s wrong with specifying a true, real size of a basic type? It shouldn’t do any harm? If yes, then why GLib’s doesn’t use this feature ?