On 5/30/07, Brian J. Tarricone <[EMAIL PROTECTED]> wrote:
> Using an idle
> function will chew through CPU cycles while the application is
> otherwise idle (really hurts laptop battery performance, for one
> thing).  Another option is a timeout using g_timeout_add(), but the
> correct approach would be to add a custom GSource that is only invoked
> when it needs to be.

I have a (slightly) similar problem with my application. It has (my
own) LISP-like programming language embedded for scripting. The
problem is when to trigger a garbage collect (other than on heap-full,
of course).

When I start processing something I use g_idle_add() to add a run-once
idle handler. When this fires, it does a g_timeout_add() with a 1
second delay. If there's already a timeout running, it destroys the
old timeout and sets a new one. Finally, when the timeout fires, it
does the garbage collect.

With this scheme you get the cleanup after a second of inactivity, and
no busy-waiting, which works for me, anyway. You'd need to watch out
for things like flashing cursors delaying cleanup forever I guess.

John
_______________________________________________
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list

Reply via email to