Re: [gtk-list] help w/ gtk_timeout_add



Ionutz Borcoman wrote:
> 
> "Kurt V. Hindenburg" wrote:
> >
> > // long...
> >
> > Hello all,
> >
> >  I'm having troubles using gtk_timeout_add in C++ (VDK variety).  I
> > have a program in C that runs fine using gtk_timeout_add.
> > However, in C++/VDK I get some warnings I'm confused about and
> > when the program runs it eats up all the CPU and is very sluggish.
> > I'm fairly sure the problem is gtk_timeout_add cause I'm using
> > canvaswin.cc (VDK) as example code.
> > I'm not an expert at C++, so perhaps it's just a C++ thing.
> >
> >  First off, are there any example of using gtk_timeout_add in C++?
> >
> > Here's my attempt:
> >
> > timerId = gtk_timeout_add ( 10 , AntWin::timeout_fn,this);
> >
> > The warning I get is:
> > antwin.cc:90: warning: converting from `gint (AntWin::*)(void *)'
> > to `gint (*)(void *)'
> 
> In general, you'll have to declare your functions as static if you want
> to use them with the gtk signaling system.
> 
> But better use a VDKTimer and connect your function with:
> 
> DEFINE_SIGNAL_MAP(MyForm,VDKForm)
>   ON_SIGNAL( _timer, timer_tick_signal, OnTimerTick)
>   END_SIGNAL_MAP;
> 
> bool
> MyForm::OnTimerTick(VDKObject *)
> {
>         ...;
>         return true;
> }
> 
> About the problem of programs being slow with gtk_timeout_add: try to
> increase the timer tick. I think the program will eat all your CPU if
> you get too many timer events.
> 
> Other problem with idle and timer stuff can come from the fact that VDK
> uses the idle to do garbage collection. Maybe this can be improved, but
> Mario is the one who can tell you more. Mario ?
> 
> Ionutz
> --
> Mental backup in progress - Do Not Disturb!
> --
> http://borco-ei.eng.hokudai.ac.jp/~borco/

Ionutz suggestion is right, you have to pass to gtk+ sygnal connect  absolute 
function addresses not  member class offset addrress as you are doing.  So
passing a global or a static class function is a (not very elegant) solution.
Or use a VDKTimer as Ionutz suggest.
Ion: 
VDK does not use idle callback for garbage collection, so no problem at  all
with cpu sharing time, furthermore interleaved cg must be explicitely set by
the user and this should not be the case.
hope this helps.
/mario

--
Mario Motta
AI Research Group - Rimini
mmotta@guest.net
http://www.guest.net/homepages/mmotta/VDKHome/index.htm



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