⚝
One Hat Cyber Team
⚝
Your IP:
216.73.216.10
Server IP:
157.245.101.34
Server:
Linux skvinfotech-website 5.4.0-131-generic #147-Ubuntu SMP Fri Oct 14 17:07:22 UTC 2022 x86_64
Server Software:
Apache/2.4.41 (Ubuntu)
PHP Version:
7.4.33
Buat File
|
Buat Folder
Eksekusi
Dir :
~
/
usr
/
share
/
doc
/
libglib2.0-doc
/
glib
/
View File Name :
glib-Reference-counting.html
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>Reference counting: GLib Reference Manual</title> <meta name="generator" content="DocBook XSL Stylesheets V1.79.1"> <link rel="home" href="index.html" title="GLib Reference Manual"> <link rel="up" href="glib-data-types.html" title="GLib Data Types"> <link rel="prev" href="gvariant-text.html" title="GVariant Text Format"> <link rel="next" href="glib-Reference-counted-data.html" title="Reference counted data"> <meta name="generator" content="GTK-Doc V1.32 (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" id="top" width="100%" summary="Navigation header" cellpadding="2" cellspacing="5"><tr valign="middle"> <td width="100%" align="left" class="shortcuts"> <a href="#" class="shortcut">Top</a><span id="nav_description"> <span class="dim">|</span> <a href="#glib-Reference-counting.description" class="shortcut">Description</a></span> </td> <td><a accesskey="h" href="index.html"><img src="home.png" width="16" height="16" border="0" alt="Home"></a></td> <td><a accesskey="u" href="glib-data-types.html"><img src="up.png" width="16" height="16" border="0" alt="Up"></a></td> <td><a accesskey="p" href="gvariant-text.html"><img src="left.png" width="16" height="16" border="0" alt="Prev"></a></td> <td><a accesskey="n" href="glib-Reference-counted-data.html"><img src="right.png" width="16" height="16" border="0" alt="Next"></a></td> </tr></table> <div class="refentry"> <a name="glib-Reference-counting"></a><div class="titlepage"></div> <div class="refnamediv"><table width="100%"><tr> <td valign="top"> <h2><span class="refentrytitle"><a name="glib-Reference-counting.top_of_page"></a>Reference counting</span></h2> <p>Reference counting — Reference counting types and functions</p> </td> <td class="gallery_image" valign="top" align="right"></td> </tr></table></div> <div class="refsect1"> <a name="glib-Reference-counting.functions"></a><h2>Functions</h2> <div class="informaltable"><table class="informaltable" width="100%" border="0"> <colgroup> <col width="150px" class="functions_proto_type"> <col class="functions_proto_name"> </colgroup> <tbody> <tr> <td class="function_type"> <span class="returnvalue">void</span> </td> <td class="function_name"> <a class="link" href="glib-Reference-counting.html#g-ref-count-init" title="g_ref_count_init ()">g_ref_count_init</a> <span class="c_punctuation">()</span> </td> </tr> <tr> <td class="function_type"> <span class="returnvalue">void</span> </td> <td class="function_name"> <a class="link" href="glib-Reference-counting.html#g-ref-count-inc" title="g_ref_count_inc ()">g_ref_count_inc</a> <span class="c_punctuation">()</span> </td> </tr> <tr> <td class="function_type"> <a class="link" href="glib-Basic-Types.html#gboolean" title="gboolean"><span class="returnvalue">gboolean</span></a> </td> <td class="function_name"> <a class="link" href="glib-Reference-counting.html#g-ref-count-dec" title="g_ref_count_dec ()">g_ref_count_dec</a> <span class="c_punctuation">()</span> </td> </tr> <tr> <td class="function_type"> <a class="link" href="glib-Basic-Types.html#gboolean" title="gboolean"><span class="returnvalue">gboolean</span></a> </td> <td class="function_name"> <a class="link" href="glib-Reference-counting.html#g-ref-count-compare" title="g_ref_count_compare ()">g_ref_count_compare</a> <span class="c_punctuation">()</span> </td> </tr> <tr> <td class="function_type"> <span class="returnvalue">void</span> </td> <td class="function_name"> <a class="link" href="glib-Reference-counting.html#g-atomic-ref-count-init" title="g_atomic_ref_count_init ()">g_atomic_ref_count_init</a> <span class="c_punctuation">()</span> </td> </tr> <tr> <td class="function_type"> <span class="returnvalue">void</span> </td> <td class="function_name"> <a class="link" href="glib-Reference-counting.html#g-atomic-ref-count-inc" title="g_atomic_ref_count_inc ()">g_atomic_ref_count_inc</a> <span class="c_punctuation">()</span> </td> </tr> <tr> <td class="function_type"> <a class="link" href="glib-Basic-Types.html#gboolean" title="gboolean"><span class="returnvalue">gboolean</span></a> </td> <td class="function_name"> <a class="link" href="glib-Reference-counting.html#g-atomic-ref-count-dec" title="g_atomic_ref_count_dec ()">g_atomic_ref_count_dec</a> <span class="c_punctuation">()</span> </td> </tr> <tr> <td class="function_type"> <a class="link" href="glib-Basic-Types.html#gboolean" title="gboolean"><span class="returnvalue">gboolean</span></a> </td> <td class="function_name"> <a class="link" href="glib-Reference-counting.html#g-atomic-ref-count-compare" title="g_atomic_ref_count_compare ()">g_atomic_ref_count_compare</a> <span class="c_punctuation">()</span> </td> </tr> </tbody> </table></div> </div> <div class="refsect1"> <a name="glib-Reference-counting.other"></a><h2>Types and Values</h2> <div class="informaltable"><table class="informaltable" width="100%" border="0"> <colgroup> <col width="150px" class="other_proto_type"> <col class="other_proto_name"> </colgroup> <tbody> <tr> <td class="typedef_keyword">typedef</td> <td class="function_name"><a class="link" href="glib-Reference-counting.html#grefcount" title="grefcount">grefcount</a></td> </tr> <tr> <td class="typedef_keyword">typedef</td> <td class="function_name"><a class="link" href="glib-Reference-counting.html#gatomicrefcount" title="gatomicrefcount">gatomicrefcount</a></td> </tr> </tbody> </table></div> </div> <div class="refsect1"> <a name="glib-Reference-counting.includes"></a><h2>Includes</h2> <pre class="synopsis">#include <glib.h> #include <glib/gi18n.h> </pre> </div> <div class="refsect1"> <a name="glib-Reference-counting.description"></a><h2>Description</h2> <p>Reference counting is a garbage collection mechanism that is based on assigning a counter to a data type, or any memory area; the counter is increased whenever a new reference to that data type is acquired, and decreased whenever the reference is released. Once the last reference is released, the resources associated to that data type are freed.</p> <p>GLib uses reference counting in many of its data types, and provides the <a class="link" href="glib-Reference-counting.html#grefcount" title="grefcount"><span class="type">grefcount</span></a> and <a class="link" href="glib-Reference-counting.html#gatomicrefcount" title="gatomicrefcount"><span class="type">gatomicrefcount</span></a> types to implement safe and atomic reference counting semantics in new data types.</p> <p>It is important to note that <a class="link" href="glib-Reference-counting.html#grefcount" title="grefcount"><span class="type">grefcount</span></a> and <a class="link" href="glib-Reference-counting.html#gatomicrefcount" title="gatomicrefcount"><span class="type">gatomicrefcount</span></a> should be considered completely opaque types; you should always use the provided API to increase and decrease the counters, and you should never check their content directly, or compare their content with other values.</p> </div> <div class="refsect1"> <a name="glib-Reference-counting.functions_details"></a><h2>Functions</h2> <div class="refsect2"> <a name="g-ref-count-init"></a><h3>g_ref_count_init ()</h3> <pre class="programlisting"><span class="returnvalue">void</span> g_ref_count_init (<em class="parameter"><code><a class="link" href="glib-Reference-counting.html#grefcount" title="grefcount"><span class="type">grefcount</span></a> *rc</code></em>);</pre> <p>Initializes a reference count variable.</p> <div class="refsect3"> <a name="g-ref-count-init.parameters"></a><h4>Parameters</h4> <div class="informaltable"><table class="informaltable" width="100%" border="0"> <colgroup> <col width="150px" class="parameters_name"> <col class="parameters_description"> <col width="200px" class="parameters_annotations"> </colgroup> <tbody><tr> <td class="parameter_name"><p>rc</p></td> <td class="parameter_description"><p>the address of a reference count variable</p></td> <td class="parameter_annotations"> </td> </tr></tbody> </table></div> </div> <p class="since">Since: <a class="link" href="api-index-2-58.html#api-index-2.58">2.58</a></p> </div> <hr> <div class="refsect2"> <a name="g-ref-count-inc"></a><h3>g_ref_count_inc ()</h3> <pre class="programlisting"><span class="returnvalue">void</span> g_ref_count_inc (<em class="parameter"><code><a class="link" href="glib-Reference-counting.html#grefcount" title="grefcount"><span class="type">grefcount</span></a> *rc</code></em>);</pre> <p>Increases the reference count.</p> <div class="refsect3"> <a name="g-ref-count-inc.parameters"></a><h4>Parameters</h4> <div class="informaltable"><table class="informaltable" width="100%" border="0"> <colgroup> <col width="150px" class="parameters_name"> <col class="parameters_description"> <col width="200px" class="parameters_annotations"> </colgroup> <tbody><tr> <td class="parameter_name"><p>rc</p></td> <td class="parameter_description"><p>the address of a reference count variable</p></td> <td class="parameter_annotations"> </td> </tr></tbody> </table></div> </div> <p class="since">Since: <a class="link" href="api-index-2-58.html#api-index-2.58">2.58</a></p> </div> <hr> <div class="refsect2"> <a name="g-ref-count-dec"></a><h3>g_ref_count_dec ()</h3> <pre class="programlisting"><a class="link" href="glib-Basic-Types.html#gboolean" title="gboolean"><span class="returnvalue">gboolean</span></a> g_ref_count_dec (<em class="parameter"><code><a class="link" href="glib-Reference-counting.html#grefcount" title="grefcount"><span class="type">grefcount</span></a> *rc</code></em>);</pre> <p>Decreases the reference count.</p> <div class="refsect3"> <a name="g-ref-count-dec.parameters"></a><h4>Parameters</h4> <div class="informaltable"><table class="informaltable" width="100%" border="0"> <colgroup> <col width="150px" class="parameters_name"> <col class="parameters_description"> <col width="200px" class="parameters_annotations"> </colgroup> <tbody><tr> <td class="parameter_name"><p>rc</p></td> <td class="parameter_description"><p>the address of a reference count variable</p></td> <td class="parameter_annotations"> </td> </tr></tbody> </table></div> </div> <div class="refsect3"> <a name="g-ref-count-dec.returns"></a><h4>Returns</h4> <p> <a class="link" href="glib-Standard-Macros.html#TRUE:CAPS" title="TRUE"><code class="literal">TRUE</code></a> if the reference count reached 0, and <a class="link" href="glib-Standard-Macros.html#FALSE:CAPS" title="FALSE"><code class="literal">FALSE</code></a> otherwise</p> </div> <p class="since">Since: <a class="link" href="api-index-2-58.html#api-index-2.58">2.58</a></p> </div> <hr> <div class="refsect2"> <a name="g-ref-count-compare"></a><h3>g_ref_count_compare ()</h3> <pre class="programlisting"><a class="link" href="glib-Basic-Types.html#gboolean" title="gboolean"><span class="returnvalue">gboolean</span></a> g_ref_count_compare (<em class="parameter"><code><a class="link" href="glib-Reference-counting.html#grefcount" title="grefcount"><span class="type">grefcount</span></a> *rc</code></em>, <em class="parameter"><code><a class="link" href="glib-Basic-Types.html#gint" title="gint"><span class="type">gint</span></a> val</code></em>);</pre> <p>Compares the current value of <em class="parameter"><code>rc</code></em> with <em class="parameter"><code>val</code></em> .</p> <div class="refsect3"> <a name="g-ref-count-compare.parameters"></a><h4>Parameters</h4> <div class="informaltable"><table class="informaltable" width="100%" border="0"> <colgroup> <col width="150px" class="parameters_name"> <col class="parameters_description"> <col width="200px" class="parameters_annotations"> </colgroup> <tbody> <tr> <td class="parameter_name"><p>rc</p></td> <td class="parameter_description"><p>the address of a reference count variable</p></td> <td class="parameter_annotations"> </td> </tr> <tr> <td class="parameter_name"><p>val</p></td> <td class="parameter_description"><p>the value to compare</p></td> <td class="parameter_annotations"> </td> </tr> </tbody> </table></div> </div> <div class="refsect3"> <a name="g-ref-count-compare.returns"></a><h4>Returns</h4> <p> <a class="link" href="glib-Standard-Macros.html#TRUE:CAPS" title="TRUE"><code class="literal">TRUE</code></a> if the reference count is the same as the given value</p> </div> <p class="since">Since: <a class="link" href="api-index-2-58.html#api-index-2.58">2.58</a></p> </div> <hr> <div class="refsect2"> <a name="g-atomic-ref-count-init"></a><h3>g_atomic_ref_count_init ()</h3> <pre class="programlisting"><span class="returnvalue">void</span> g_atomic_ref_count_init (<em class="parameter"><code><a class="link" href="glib-Reference-counting.html#gatomicrefcount" title="gatomicrefcount"><span class="type">gatomicrefcount</span></a> *arc</code></em>);</pre> <p>Initializes a reference count variable.</p> <div class="refsect3"> <a name="g-atomic-ref-count-init.parameters"></a><h4>Parameters</h4> <div class="informaltable"><table class="informaltable" width="100%" border="0"> <colgroup> <col width="150px" class="parameters_name"> <col class="parameters_description"> <col width="200px" class="parameters_annotations"> </colgroup> <tbody><tr> <td class="parameter_name"><p>arc</p></td> <td class="parameter_description"><p>the address of an atomic reference count variable</p></td> <td class="parameter_annotations"> </td> </tr></tbody> </table></div> </div> <p class="since">Since: <a class="link" href="api-index-2-58.html#api-index-2.58">2.58</a></p> </div> <hr> <div class="refsect2"> <a name="g-atomic-ref-count-inc"></a><h3>g_atomic_ref_count_inc ()</h3> <pre class="programlisting"><span class="returnvalue">void</span> g_atomic_ref_count_inc (<em class="parameter"><code><a class="link" href="glib-Reference-counting.html#gatomicrefcount" title="gatomicrefcount"><span class="type">gatomicrefcount</span></a> *arc</code></em>);</pre> <p>Atomically increases the reference count.</p> <div class="refsect3"> <a name="g-atomic-ref-count-inc.parameters"></a><h4>Parameters</h4> <div class="informaltable"><table class="informaltable" width="100%" border="0"> <colgroup> <col width="150px" class="parameters_name"> <col class="parameters_description"> <col width="200px" class="parameters_annotations"> </colgroup> <tbody><tr> <td class="parameter_name"><p>arc</p></td> <td class="parameter_description"><p>the address of an atomic reference count variable</p></td> <td class="parameter_annotations"> </td> </tr></tbody> </table></div> </div> <p class="since">Since: <a class="link" href="api-index-2-58.html#api-index-2.58">2.58</a></p> </div> <hr> <div class="refsect2"> <a name="g-atomic-ref-count-dec"></a><h3>g_atomic_ref_count_dec ()</h3> <pre class="programlisting"><a class="link" href="glib-Basic-Types.html#gboolean" title="gboolean"><span class="returnvalue">gboolean</span></a> g_atomic_ref_count_dec (<em class="parameter"><code><a class="link" href="glib-Reference-counting.html#gatomicrefcount" title="gatomicrefcount"><span class="type">gatomicrefcount</span></a> *arc</code></em>);</pre> <p>Atomically decreases the reference count.</p> <div class="refsect3"> <a name="g-atomic-ref-count-dec.parameters"></a><h4>Parameters</h4> <div class="informaltable"><table class="informaltable" width="100%" border="0"> <colgroup> <col width="150px" class="parameters_name"> <col class="parameters_description"> <col width="200px" class="parameters_annotations"> </colgroup> <tbody><tr> <td class="parameter_name"><p>arc</p></td> <td class="parameter_description"><p>the address of an atomic reference count variable</p></td> <td class="parameter_annotations"> </td> </tr></tbody> </table></div> </div> <div class="refsect3"> <a name="g-atomic-ref-count-dec.returns"></a><h4>Returns</h4> <p> <a class="link" href="glib-Standard-Macros.html#TRUE:CAPS" title="TRUE"><code class="literal">TRUE</code></a> if the reference count reached 0, and <a class="link" href="glib-Standard-Macros.html#FALSE:CAPS" title="FALSE"><code class="literal">FALSE</code></a> otherwise</p> </div> <p class="since">Since: <a class="link" href="api-index-2-58.html#api-index-2.58">2.58</a></p> </div> <hr> <div class="refsect2"> <a name="g-atomic-ref-count-compare"></a><h3>g_atomic_ref_count_compare ()</h3> <pre class="programlisting"><a class="link" href="glib-Basic-Types.html#gboolean" title="gboolean"><span class="returnvalue">gboolean</span></a> g_atomic_ref_count_compare (<em class="parameter"><code><a class="link" href="glib-Reference-counting.html#gatomicrefcount" title="gatomicrefcount"><span class="type">gatomicrefcount</span></a> *arc</code></em>, <em class="parameter"><code><a class="link" href="glib-Basic-Types.html#gint" title="gint"><span class="type">gint</span></a> val</code></em>);</pre> <p>Atomically compares the current value of <em class="parameter"><code>arc</code></em> with <em class="parameter"><code>val</code></em> .</p> <div class="refsect3"> <a name="g-atomic-ref-count-compare.parameters"></a><h4>Parameters</h4> <div class="informaltable"><table class="informaltable" width="100%" border="0"> <colgroup> <col width="150px" class="parameters_name"> <col class="parameters_description"> <col width="200px" class="parameters_annotations"> </colgroup> <tbody> <tr> <td class="parameter_name"><p>arc</p></td> <td class="parameter_description"><p>the address of an atomic reference count variable</p></td> <td class="parameter_annotations"> </td> </tr> <tr> <td class="parameter_name"><p>val</p></td> <td class="parameter_description"><p>the value to compare</p></td> <td class="parameter_annotations"> </td> </tr> </tbody> </table></div> </div> <div class="refsect3"> <a name="g-atomic-ref-count-compare.returns"></a><h4>Returns</h4> <p> <a class="link" href="glib-Standard-Macros.html#TRUE:CAPS" title="TRUE"><code class="literal">TRUE</code></a> if the reference count is the same as the given value</p> </div> <p class="since">Since: <a class="link" href="api-index-2-58.html#api-index-2.58">2.58</a></p> </div> </div> <div class="refsect1"> <a name="glib-Reference-counting.other_details"></a><h2>Types and Values</h2> <div class="refsect2"> <a name="grefcount"></a><h3>grefcount</h3> <pre class="programlisting">typedef gint grefcount; </pre> <p>A type for implementing non-atomic reference count semantics.</p> <p>Use <a class="link" href="glib-Reference-counting.html#g-ref-count-init" title="g_ref_count_init ()"><code class="function">g_ref_count_init()</code></a> to initialize it; <a class="link" href="glib-Reference-counting.html#g-ref-count-inc" title="g_ref_count_inc ()"><code class="function">g_ref_count_inc()</code></a> to increase the counter, and <a class="link" href="glib-Reference-counting.html#g-ref-count-dec" title="g_ref_count_dec ()"><code class="function">g_ref_count_dec()</code></a> to decrease it.</p> <p>It is safe to use <a class="link" href="glib-Reference-counting.html#grefcount" title="grefcount"><span class="type">grefcount</span></a> only if you're expecting to operate on the reference counter from a single thread. It is entirely up to you to ensure that all reference count changes happen in the same thread.</p> <p>See also: <a class="link" href="glib-Reference-counting.html#gatomicrefcount" title="gatomicrefcount"><span class="type">gatomicrefcount</span></a></p> <p class="since">Since: <a class="link" href="api-index-2-58.html#api-index-2.58">2.58</a></p> </div> <hr> <div class="refsect2"> <a name="gatomicrefcount"></a><h3>gatomicrefcount</h3> <pre class="programlisting">typedef volatile gint gatomicrefcount; </pre> <p>A type for implementing atomic reference count semantics.</p> <p>Use <a class="link" href="glib-Reference-counting.html#g-atomic-ref-count-init" title="g_atomic_ref_count_init ()"><code class="function">g_atomic_ref_count_init()</code></a> to initialize it; <a class="link" href="glib-Reference-counting.html#g-atomic-ref-count-inc" title="g_atomic_ref_count_inc ()"><code class="function">g_atomic_ref_count_inc()</code></a> to increase the counter, and <a class="link" href="glib-Reference-counting.html#g-atomic-ref-count-dec" title="g_atomic_ref_count_dec ()"><code class="function">g_atomic_ref_count_dec()</code></a> to decrease it.</p> <p>It is safe to use <a class="link" href="glib-Reference-counting.html#gatomicrefcount" title="gatomicrefcount"><span class="type">gatomicrefcount</span></a> if you're expecting to operate on the reference counter from multiple threads.</p> <p>See also: <a class="link" href="glib-Reference-counting.html#grefcount" title="grefcount"><span class="type">grefcount</span></a></p> <p class="since">Since: <a class="link" href="api-index-2-58.html#api-index-2.58">2.58</a></p> </div> </div> </div> <div class="footer"> <hr>Generated by GTK-Doc V1.32</div> </body> </html>