Re: Run Loop Memory Management
- From: jcupitt gmail com
- Cc: gtk-app-devel-list gnome org
- Subject: Re: Run Loop Memory Management
- Date: Wed, 30 May 2007 11:37:38 +0100
On 5/30/07, Brian J. Tarricone <bjt23 cornell edu> 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
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]