Re: a GList of g_object_add_weak_pointer()s



Exactly, except for the `dummy area' which reveals some
misunderstanding.  The pointer passed to g_list_append() is
just a value.

I think I may picked that up from the book. Its example it gives allocates a pointer to an int, puts a value in that space, and then adds the pointer to the list.

If you for some reason don't know the value
at the time you are creating the item for it, just assign
the right value to item->data later, pass it to
g_object_add_weak_pointer(), or whatever.

However I don't understand why you can't do just this:

  p = some_object_new();
  item = g_list_append(NULL, p);
  g_object_add_weak_pointer(p, &item->data);
  list = g_list_concat(item, list);
  /* or g_list_concat(l, i), but that's inefficient, it's
   * better to construct the list in reverse order and then
   * do g_list_reverse() */

No particular reason save not really noticing the g_list_concat() call before.

However, if the data structures do not change (or seldom
change) after construction, it would not use lists, they
bring no advantage in this case and they have bad data
locality, pointer arrays would be better.

The structure isn't expected to change much after construction, although the length is not known ahead of time. At present I don't anticipate performance to be an issue here - this is really just for the one shot "Hey, I'm initialized, you can finish init now" case.

thanks,

rick jones



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]