glib-Timers.html   [plain text]


<html><head><meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"><title>Timers</title><meta name="generator" content="DocBook XSL Stylesheets V1.65.1"><link rel="home" href="index.html" title="GLib Reference Manual"><link rel="up" href="glib-utilities.html" title="GLib Utilities"><link rel="previous" href="glib-Automatic-String-Completion.html" title="Automatic String Completion"><link rel="next" href="glib-Spawning-Processes.html" title="Spawning Processes"><link rel="chapter" href="glib.html" title="GLib Overview"><link rel="refentry" href="glib-building.html" title="Compiling the GLib package"><link rel="refentry" href="glib-cross-compiling.html" title="Cross-compiling the GLib package"><link rel="refentry" href="glib-compiling.html" title="Compiling GLib Applications"><link rel="refentry" href="glib-running.html" title="Running GLib Applications"><link rel="refentry" href="glib-changes.html" title="Changes to GLib"><link rel="refentry" href="glib-resources.html" title="Mailing lists and bug reports"><link rel="chapter" href="glib-fundamentals.html" title="GLib Fundamentals"><link rel="refentry" href="glib-Basic-Types.html" title="Basic Types"><link rel="refentry" href="glib-Limits-of-Basic-Types.html" title="Limits of Basic Types"><link rel="refentry" href="glib-Standard-Macros.html" title="Standard Macros"><link rel="refentry" href="glib-Type-Conversion-Macros.html" title="Type Conversion Macros"><link rel="refentry" href="glib-Byte-Order-Macros.html" title="Byte Order Macros"><link rel="refentry" href="glib-Numerical-Definitions.html" title="Numerical Definitions"><link rel="refentry" href="glib-Miscellaneous-Macros.html" title="Miscellaneous Macros"><link rel="refentry" href="glib-Atomic-Operations.html" title="Atomic Operations"><link rel="chapter" href="glib-core.html" title="GLib Core Application Support"><link rel="refentry" href="glib-The-Main-Event-Loop.html" title="The Main Event Loop"><link rel="refentry" href="glib-Threads.html" title="
Threads"><link rel="refentry" href="glib-Thread-Pools.html" title="Thread Pools"><link rel="refentry" href="glib-Asynchronous-Queues.html" title="Asynchronous Queues"><link rel="refentry" href="glib-Dynamic-Loading-of-Modules.html" title="Dynamic Loading of Modules"><link rel="refentry" href="glib-Memory-Allocation.html" title="Memory Allocation"><link rel="refentry" href="glib-IO-Channels.html" title="IO Channels"><link rel="refentry" href="glib-Error-Reporting.html" title="Error Reporting"><link rel="refentry" href="glib-Warnings-and-Assertions.html" title="Message Output and Debugging Functions"><link rel="refentry" href="glib-Message-Logging.html" title="Message Logging"><link rel="chapter" href="glib-utilities.html" title="GLib Utilities"><link rel="refentry" href="glib-String-Utility-Functions.html" title="String Utility Functions"><link rel="refentry" href="glib-Character-Set-Conversion.html" title="Character Set Conversion"><link rel="refentry" href="glib-Unicode-Manipulation.html" title="Unicode Manipulation"><link rel="refentry" href="glib-I18N.html" title="Internationalization"><link rel="refentry" href="glib-Date-and-Time-Functions.html" title="Date and Time Functions"><link rel="refentry" href="glib-Random-Numbers.html" title="Random Numbers"><link rel="refentry" href="glib-Hook-Functions.html" title="Hook Functions"><link rel="refentry" href="glib-Miscellaneous-Utility-Functions.html" title="Miscellaneous Utility Functions"><link rel="refentry" href="glib-Lexical-Scanner.html" title="Lexical Scanner"><link rel="refentry" href="glib-Automatic-String-Completion.html" title="Automatic String Completion"><link rel="refentry" href="glib-Timers.html" title="Timers"><link rel="refentry" href="glib-Spawning-Processes.html" title="Spawning Processes"><link rel="refentry" href="glib-File-Utilities.html" title="File Utilities"><link rel="refentry" href="glib-Shell-related-Utilities.html" title="Shell-related Utilities"><link rel="refentry" href="glib-Glob-style-pattern-matching.html" title="Glob-style pattern matching"><link rel="refentry" href="glib-Simple-XML-Subset-Parser.html" title="Simple XML Subset Parser"><link rel="refentry" href="glib-Windows-Compatability-Functions.html" title="Windows Compatibility Functions"><link rel="chapter" href="glib-data-types.html" title="GLib Data Types"><link rel="refentry" href="glib-Memory-Chunks.html" title="Memory Chunks"><link rel="refentry" href="glib-Doubly-Linked-Lists.html" title="Doubly-Linked Lists"><link rel="refentry" href="glib-Singly-Linked-Lists.html" title="Singly-Linked Lists"><link rel="refentry" href="glib-Double-ended-Queues.html" title="Double-ended Queues"><link rel="refentry" href="glib-Trash-Stacks.html" title="Trash Stacks"><link rel="refentry" href="glib-Hash-Tables.html" title="Hash Tables"><link rel="refentry" href="glib-Strings.html" title="Strings"><link rel="refentry" href="glib-String-Chunks.html" title="String Chunks"><link rel="refentry" href="glib-Arrays.html" title="Arrays"><link rel="refentry" href="glib-Pointer-Arrays.html" title="Pointer Arrays"><link rel="refentry" href="glib-Byte-Arrays.html" title="Byte Arrays"><link rel="refentry" href="glib-Balanced-Binary-Trees.html" title="Balanced Binary Trees"><link rel="refentry" href="glib-N-ary-Trees.html" title="N-ary Trees"><link rel="refentry" href="glib-Quarks.html" title="Quarks"><link rel="refentry" href="glib-Keyed-Data-Lists.html" title="Keyed Data Lists"><link rel="refentry" href="glib-Datasets.html" title="Datasets"><link rel="refentry" href="glib-Relations-and-Tuples.html" title="Relations and Tuples"><link rel="refentry" href="glib-Caches.html" title="Caches"><link rel="refentry" href="glib-Memory-Allocators.html" title="Memory Allocators"><link rel="chapter" href="tools.html" title="GLib Tools"><link rel="refentry" href="glib-gettextize.html" title="glib-gettextize"><link rel="index" href="ix01.html" title="Index"><link rel="section" href="glib-Timers.html#id3203180" title="Description"><link rel="section" href="glib-Timers.html#id3203209" title="Details"><meta name="generator" content="GTK-Doc V1.2 (XML mode)"><link rel="stylesheet" href="style.css" type="text/css"></head><body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><table class="navigation" width="100%" summary="Navigation header" cellpadding="2" cellspacing="2"><tr valign="middle"><td><a accesskey="p" href="glib-Automatic-String-Completion.html"><img src="left.png" width="24" height="24" border="0" alt="Prev"></a></td><td><a accesskey="u" href="glib-utilities.html"><img src="up.png" width="24" height="24" border="0" alt="Up"></a></td><td><a accesskey="h" href="index.html"><img src="home.png" width="24" height="24" border="0" alt="Home"></a></td><th width="100%" align="center">GLib Reference Manual</th><td><a accesskey="n" href="glib-Spawning-Processes.html"><img src="right.png" width="24" height="24" border="0" alt="Next"></a></td></tr></table><div class="refentry" lang="en"><a name="glib-Timers"></a><div class="titlepage"><div></div><div></div></div><div class="refnamediv"><h2><span class="refentrytitle">Timers</span></h2><p>Timers &#8212; 
keep track of elapsed time.</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">

#include &lt;glib.h&gt;


struct      <a href="glib-Timers.html#GTimer">GTimer</a>;
<a href="glib-Timers.html#GTimer">GTimer</a>*     <a href="glib-Timers.html#g-timer-new">g_timer_new</a>                     (void);
void        <a href="glib-Timers.html#g-timer-start">g_timer_start</a>                   (<a href="glib-Timers.html#GTimer">GTimer</a> *timer);
void        <a href="glib-Timers.html#g-timer-stop">g_timer_stop</a>                    (<a href="glib-Timers.html#GTimer">GTimer</a> *timer);
void        <a href="glib-Timers.html#g-timer-continue">g_timer_continue</a>                (<a href="glib-Timers.html#GTimer">GTimer</a> *timer);
<a href="glib-Basic-Types.html#gdouble">gdouble</a>     <a href="glib-Timers.html#g-timer-elapsed">g_timer_elapsed</a>                 (<a href="glib-Timers.html#GTimer">GTimer</a> *timer,
                                             <a href="glib-Basic-Types.html#gulong">gulong</a> *microseconds);
void        <a href="glib-Timers.html#g-timer-reset">g_timer_reset</a>                   (<a href="glib-Timers.html#GTimer">GTimer</a> *timer);
void        <a href="glib-Timers.html#g-timer-destroy">g_timer_destroy</a>                 (<a href="glib-Timers.html#GTimer">GTimer</a> *timer);
</pre></div><div class="refsect1" lang="en"><a name="id3203180"></a><h2>Description</h2><p>
<a href="glib-Timers.html#GTimer"><span class="type">GTimer</span></a> records a start time, and counts microseconds elapsed since that time.
This is done somewhat differently on different platforms, and can be tricky to
get exactly right, so <a href="glib-Timers.html#GTimer"><span class="type">GTimer</span></a> provides a portable/convenient interface.
</p></div><div class="refsect1" lang="en"><a name="id3203209"></a><h2>Details</h2><div class="refsect2" lang="en"><a name="id3203214"></a><h3><a name="GTimer"></a>struct GTimer</h3><a class="indexterm" name="id3203225"></a><pre class="programlisting">struct GTimer;</pre><p>
Opaque datatype that records a start time. 
</p></div><hr><div class="refsect2" lang="en"><a name="id3203241"></a><h3><a name="g-timer-new"></a>g_timer_new ()</h3><a class="indexterm" name="id3203252"></a><pre class="programlisting"><a href="glib-Timers.html#GTimer">GTimer</a>*     g_timer_new                     (void);</pre><p>
Creates a new timer, and starts timing (i.e. <a href="glib-Timers.html#g-timer-start"><tt class="function">g_timer_start()</tt></a> is implicitly
called for you).
</p><div class="variablelist"><table border="0"><col align="left" valign="top"><tbody><tr><td><span class="term"><span class="emphasis"><em>Returns</em></span> :</span></td><td>a new <a href="glib-Timers.html#GTimer"><span class="type">GTimer</span></a>.


</td></tr></tbody></table></div></div><hr><div class="refsect2" lang="en"><a name="id3203307"></a><h3><a name="g-timer-start"></a>g_timer_start ()</h3><a class="indexterm" name="id3203318"></a><pre class="programlisting">void        g_timer_start                   (<a href="glib-Timers.html#GTimer">GTimer</a> *timer);</pre><p>
Marks a start time, so that future calls to <a href="glib-Timers.html#g-timer-elapsed"><tt class="function">g_timer_elapsed()</tt></a> will report the
time since <a href="glib-Timers.html#g-timer-start"><tt class="function">g_timer_start()</tt></a> was called. <a href="glib-Timers.html#g-timer-new"><tt class="function">g_timer_new()</tt></a> automatically marks the
start time, so no need to call <a href="glib-Timers.html#g-timer-start"><tt class="function">g_timer_start()</tt></a> immediately after creating the
timer.
</p><div class="variablelist"><table border="0"><col align="left" valign="top"><tbody><tr><td><span class="term"><i class="parameter"><tt>timer</tt></i> :</span></td><td>a <a href="glib-Timers.html#GTimer"><span class="type">GTimer</span></a>.


</td></tr></tbody></table></div></div><hr><div class="refsect2" lang="en"><a name="id3203417"></a><h3><a name="g-timer-stop"></a>g_timer_stop ()</h3><a class="indexterm" name="id3203428"></a><pre class="programlisting">void        g_timer_stop                    (<a href="glib-Timers.html#GTimer">GTimer</a> *timer);</pre><p>
Marks an end time, so calls to <a href="glib-Timers.html#g-timer-elapsed"><tt class="function">g_timer_elapsed()</tt></a> will return the difference
between this end time and the start time.
</p><div class="variablelist"><table border="0"><col align="left" valign="top"><tbody><tr><td><span class="term"><i class="parameter"><tt>timer</tt></i> :</span></td><td>a <a href="glib-Timers.html#GTimer"><span class="type">GTimer</span></a>.


</td></tr></tbody></table></div></div><hr><div class="refsect2" lang="en"><a name="id3203495"></a><h3><a name="g-timer-continue"></a>g_timer_continue ()</h3><a class="indexterm" name="id3203506"></a><pre class="programlisting">void        g_timer_continue                (<a href="glib-Timers.html#GTimer">GTimer</a> *timer);</pre><p>
Resumes a timer that has previously been stopped with <a href="glib-Timers.html#g-timer-stop"><tt class="function">g_timer_stop()</tt></a>.
<a href="glib-Timers.html#g-timer-stop"><tt class="function">g_timer_stop()</tt></a> must be called before using this function.
</p><div class="variablelist"><table border="0"><col align="left" valign="top"><tbody><tr><td><span class="term"><i class="parameter"><tt>timer</tt></i> :</span></td><td>a <a href="glib-Timers.html#GTimer"><span class="type">GTimer</span></a>.
</td></tr></tbody></table></div><p>Since 2.4


</p></div><hr><div class="refsect2" lang="en"><a name="id3203587"></a><h3><a name="g-timer-elapsed"></a>g_timer_elapsed ()</h3><a class="indexterm" name="id3203598"></a><pre class="programlisting"><a href="glib-Basic-Types.html#gdouble">gdouble</a>     g_timer_elapsed                 (<a href="glib-Timers.html#GTimer">GTimer</a> *timer,
                                             <a href="glib-Basic-Types.html#gulong">gulong</a> *microseconds);</pre><p>
If <i class="parameter"><tt>timer</tt></i> has been started but not stopped, obtains the time since the timer was
started. If <i class="parameter"><tt>timer</tt></i> has been stopped, obtains the elapsed time between the time
it was started and the time it was stopped. The return value is the number of
seconds elapsed, including any fractional part. The <i class="parameter"><tt>microseconds</tt></i>
out parameter is essentially useless.
</p><div class="variablelist"><table border="0"><col align="left" valign="top"><tbody><tr><td><span class="term"><i class="parameter"><tt>timer</tt></i> :</span></td><td>a <a href="glib-Timers.html#GTimer"><span class="type">GTimer</span></a>.
</td></tr><tr><td><span class="term"><i class="parameter"><tt>microseconds</tt></i> :</span></td><td>fractional part of seconds elapsed, in microseconds
  (that is, the total number of microseconds elapsed, modulo 
   1000000)
</td></tr><tr><td><span class="term"><span class="emphasis"><em>Returns</em></span> :</span></td><td>seconds elapsed as a floating point value, including 
  any fractional part.


</td></tr></tbody></table></div></div><hr><div class="refsect2" lang="en"><a name="id3203710"></a><h3><a name="g-timer-reset"></a>g_timer_reset ()</h3><a class="indexterm" name="id3203721"></a><pre class="programlisting">void        g_timer_reset                   (<a href="glib-Timers.html#GTimer">GTimer</a> *timer);</pre><p>
This function is useless; it's fine to call <a href="glib-Timers.html#g-timer-start"><tt class="function">g_timer_start()</tt></a> on an
already-started timer to reset the start time, so <a href="glib-Timers.html#g-timer-reset"><tt class="function">g_timer_reset()</tt></a> serves no
purpose.
</p><div class="variablelist"><table border="0"><col align="left" valign="top"><tbody><tr><td><span class="term"><i class="parameter"><tt>timer</tt></i> :</span></td><td>a <a href="glib-Timers.html#GTimer"><span class="type">GTimer</span></a>.


</td></tr></tbody></table></div></div><hr><div class="refsect2" lang="en"><a name="id3203798"></a><h3><a name="g-timer-destroy"></a>g_timer_destroy ()</h3><a class="indexterm" name="id3203809"></a><pre class="programlisting">void        g_timer_destroy                 (<a href="glib-Timers.html#GTimer">GTimer</a> *timer);</pre><p>
Destroys a timer, freeing associated resources.
</p><div class="variablelist"><table border="0"><col align="left" valign="top"><tbody><tr><td><span class="term"><i class="parameter"><tt>timer</tt></i> :</span></td><td>a <a href="glib-Timers.html#GTimer"><span class="type">GTimer</span></a> to destroy.


</td></tr></tbody></table></div></div></div></div><table class="navigation" width="100%" summary="Navigation footer" cellpadding="2" cellspacing="0"><tr valign="middle"><td align="left"><a accesskey="p" href="glib-Automatic-String-Completion.html"><b>&lt;&lt; Automatic String Completion</b></a></td><td align="right"><a accesskey="n" href="glib-Spawning-Processes.html"><b>Spawning Processes &gt;&gt;</b></a></td></tr></table></body></html>