Lazy loading

Little post about a useful design pattern in GLib and GTK, written down after a question on the #gtk+ 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.

This entry was posted in C, GNOME, Hacking. Bookmark the permalink.

9 Responses to Lazy loading

  1. There is a typo in cleanup_load_items in the g_assert. It should probably be == not =.

  2. mike says:

    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?

  3. ebassi says:

    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.

  4. Pingback: James Henstridge

  5. mike says:

    Duh… I was looking at gtk_idle_add_full.

  6. Matthias Liegend says:

    I believe you meant to pass “data” rather than “store” for the third parameter of g_idle_add_full. Thanks for the example code!

  7. ebassi says:

    nelson: thanks!

    matthias: yep, fixed that :-)

  8. Pingback: Phenomena in the days of Philip » Blog Archive » GUnit documentation now online

Comments are closed.