GTK+ Forums

Discussion forum for GTK+ and Programming. Ask questions, troubleshoot problems, view and post example code, or express your opinions.
It is currently Tue Jul 29, 2014 4:37 am

All times are UTC




Post new topic Reply to topic  [ 3 posts ] 
Author Message
 Post subject: how about usig standard C library fubctions? Timer?
PostPosted: Mon May 12, 2008 12:22 pm 
Offline
GTK+ Geek

Joined: Sat May 10, 2008 1:52 pm
Posts: 54
(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


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 12, 2008 3:12 pm 
Offline
Never Seen the Sunlight

Joined: Wed Sep 21, 2005 12:07 am
Posts: 563
Location: Portland, OR USA
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.

_________________
Micah Carrick - Forum Administrator
http://www.micahcarrick.com


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 12, 2008 3:51 pm 
Offline
GTK+ Geek

Joined: Sat May 10, 2008 1:52 pm
Posts: 54
Micah, thank you! your help is invaluable.
Peter


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 3 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group