On Sat, 2008-07-19 at 09:03 +1000, Saul Lethbridge wrote:
> My application will be using an unknown number of clutter actors at
> build time. I'm wanting to create a struct of arrays that I can later
> realloc when required.
>
> struct cNode
> {
> int numNodes;
> ClutterActor *clutterArray[1];
> cairo_t *cr[1];
> };
Using a struct with an array and overallocating to make the array longer
only really works if the array is the last field of the struct so it
won't work in this case where you are trying to have two arrays in one
struct.
The easiest way to do this would probably be to make a struct to contain
a single pair and then use a GArray [1] or a GSList [2] to keep track of
them, like this:
struct cNode
{
ClutterActor *actor;
cairo_t *cr;
};
struct cNode node;
/* make the array */
GArray *array = g_array_new (FALSE, FALSE, sizeof (struct cNode));
/* add an item */
node.actor = clutter_texture_new (...);
node.cr = cairo_create (...);
g_array_append_val (array, node);
/* add another item */
node.actor = clutter_label_new (...);
node.cr = cairo_create (...);
g_array_append_val (array, node);
/* add the first actor to the stage */
g_container_add (stage, g_array_index (array,
struct cNode, 0).actor, NULL);
/* etc */
- Neil
[1] http://library.gnome.org/devel/glib/stable/glib-Arrays.html
[2] http://library.gnome.org/devel/glib/stable/glib-Singly-Linked-Lists.html
--
To unsubscribe send a mail to [EMAIL PROTECTED]