Re: newbie trap



Ross Clement wrote:
Hi. I find myself writing a program that processes the gtk gui events
itself. E.g. code vaguely similar to the pseudo-code:

while( large_compute_bound_job_not_finished )
{
  process_next_block_of_data();
  gtk_progress_bar_set_fraction( progressBar, fraction );
while ( gtk_events_pending ())
          gtk_main_iteration ();
}

Is this something that it is frequently sensible to do, or have I fallen
into a big newbie trap?

No and yes :)

Personally; I consider recursing into the main loop as a sort of hack;
typicly used when porting some code that originally drove its own main
loop, or when tweaking the responsiveness of an application thats
reached its limit of complexity and just wont be refactored, anyhow;
this hack has become more and more wide-spread and is now probably
considered "common practice" (and works quite well).

Read through this:
http://developer.gnome.org/doc/API/2.0/glib/glib-The-Main-Event-Loop.html

And then you can decide if you'd rather recurse into the main loop from
inside your source callback (or signal or whatnot); or if you'd rather
just queue a timeout function or an idle function to process another
block of data every time the main loop is idle.

The difference is subtle but your program will behave differently;
personally I feel its saner to call `return;' as much as possible.

Cheers,
                      -Tristan




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