GTK+ Forums Forum Index GTK+ Forums
Discussion forum for GTK+ and Programming. Ask questions, troubleshoot problems, view and post example code, or express your opinions.
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

how about usig standard C library fubctions? Timer?

 
Post new topic   Reply to topic    GTK+ Forums Forum Index -> GTK+ Programming
Author Message
Peter
Familiar Face


Joined: 10 May 2008
Posts: 12

PostPosted: Mon May 12, 2008 12:22 pm    Post subject: how about usig standard C library fubctions? Timer? Reply with quote

(1) I am using functions like calloc(0, ststr() etc, but I am getting warnings at compilation. Is there any penalty using these? Are ther thread-safe in GTK?
(2) Is there a timer functionality in GTK? I need to make repeated actions
each second or so. In Windows there is a message that can be used for this" WM_TIMER. Or one can create a separate thread to make the timer?
Thanks
Peter
Back to top
Micah Carrick
Never Seen the Sunlight


Joined: 21 Sep 2005
Posts: 427
Location: Portland, OR USA

PostPosted: Mon May 12, 2008 3:12 pm    Post subject: Reply with quote

Quote:
(1) I am using functions like calloc(0, ststr() etc, but I am getting warnings at compilation. Is there any penalty using these? Are ther thread-safe in GTK?


I think (operative word there is think) that the main reason for using GLib's utility functions is portability. However, when they dont' do anything differently, they simply wrap the appropriate utility function, so really, I would suggest using the ones that GLib provides. Also, I think it is bad to mix memory management functions (don't mix malloc and g_free for example). Again, I would go with the GLib functions.

Quote:
(2) Is there a timer functionality in GTK? I need to make repeated actions
each second or so. In Windows there is a message that can be used for this" WM_TIMER. Or one can create a separate thread to make the timer?


This one depends on your precision and needs.

If you just need a timer, check out GTimer.

If you need to execute a function about every x microseconds, but accuracy is not a primary concern, check out g_timeout_add (). I use this one quite often.

If you need precise timing, I'm not sure there is a pure GTK method for that (I don't think there is). However, some situations you can simply decrease your g_timeout intervals and check the time on the system and do your own math.
Back to top
Peter
Familiar Face


Joined: 10 May 2008
Posts: 12

PostPosted: Mon May 12, 2008 3:51 pm    Post subject: Reply with quote

Micah, thank you! your help is invaluable.
Peter
Back to top
Display posts from previous:   
Post new topic   Reply to topic    GTK+ Forums Forum Index -> GTK+ Programming All times are GMT
Page 1 of 1

 


Powered by phpBB © 2001, 2005 phpBB Group
CodeBB 1.0 Beta 2
Protected by Anti-Spam ACP