Lazy loading

Little post about a useful design pattern in GLib and GTK, written down after a question on the + channel

While I’m not Philip and I won’t go as far as talking about this in public, I wrote down a simple design pattern for lazy loading stuff from a list into a GtkTreeView without blocking your interface or using threads.

Lazy loading using the main loop.

9 Replies to “Lazy loading”

  1. What do you do if you need to use your GtkTreeView before it’s completely loaded? How would you force the load?

    Also, is the state definition really necessary, since the state transitions are effectively managed internally by the idle function manager?

    Nitpick: doesn’t g_idle_add_full actually take 5 parameters?

  2. aleksey: fixed, thanks :-)

    mike: I’d use the same pattern shown by philip van hoof: proxy objects and loading only stuff that is effectively shown. the state definition is just to make clear we are using a state machine; it’s also useful for checking the internal state, and for avoiding multiple reloads. as for the g_idle_add_full(): no, it takes 4 parameters: the priority, the callback, the data to pass to the callback and the function to be called when the idle is removed.

  3. Pingback: James Henstridge
  4. I believe you meant to pass “data” rather than “store” for the third parameter of g_idle_add_full. Thanks for the example code!

Comments are closed.