 |
GTK+ Forums Discussion forum for GTK+ and Programming. Ask questions, troubleshoot problems, view and post example code, or express your opinions.
|
|
|
| Author |
Message |
|
|
Peter Familiar Face
Joined: 10 May 2008 Posts: 46
|
Posted: Mon May 12, 2008 12:22 pm Post subject: how about usig standard C library fubctions? Timer? |
|
|
(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: 465 Location: Portland, OR USA
|
Posted: Mon May 12, 2008 3:12 pm Post subject: |
|
|
| 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: 46
|
Posted: Mon May 12, 2008 3:51 pm Post subject: |
|
|
Micah, thank you! your help is invaluable.
Peter |
|
| Back to top |
|
 |
|
Powered by phpBB © 2001, 2005 phpBB Group CodeBB 1.0 Beta 2
|