You’re passing a pointer to g_array_append_val. You have to pass a value or use g_array_append_vals(t1, 1). Or just use a GPtrArray if that’s what you want.
A pretty common trick is also to first g_array_set_size (a, a->len + 1) and then you get the memory for your element via g_array_index(a, a->len - 1) and now you can initialize the element, e.g. via g_strlcpy() like you’re doing in your example. E.g.: https://gitlab.gnome.org/GNOME/gtk/-/blob/master/gtk/gtksnapshot.c#L118
You can, but that won’t give you the cache contiguity you’re looking for in the way that you think it will. The storage location for the struct entity instances has to be inside the GArray for that, rather than coming from malloc(). Passing *t1 will memcpy() the data from your malloc() storage location on the heap, into the storage location in the GArray. The malloc() space will then become redundant, so you might as well not malloc() in the first place.
Timm’s second suggestion will do what you want, as will something along the lines of:
Compiler complains about the address operand & in g_array_append_val()
In file included from /usr/include/glib-2.0/glib.h:31,
from viewport_stacked.c:1:
viewport_stacked.c: In function ‘main’:
/usr/include/glib-2.0/glib/garray.h:64:59: error: lvalue required as unary ‘&’ operand
64 | #define g_array_append_val(a,v) g_array_append_vals (a, &(v), 1)
@pwithnall Since we already have a solution, makes no sense spend you time on these details. I have fixed here and I will open another topic regards the actual status of the code.