⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 glib-caches.html

📁 glid编写实例
💻 HTML
📖 第 1 页 / 共 2 页
字号:
<html xmlns:cf="http://docbook.sourceforge.net/xmlns/chunkfast/1.0"><head><meta http-equiv="Content-Type" content="text/html; charset=US-ASCII"><title>Caches</title><meta name="generator" content="DocBook XSL Stylesheets V1.69.0"><link rel="start" href="index.html" title="GLib Reference Manual"><link rel="up" href="glib-data-types.html" title="GLib Data Types"><link rel="prev" href="glib-Relations-and-Tuples.html" title="Relations and Tuples"><link rel="next" href="glib-Memory-Allocators.html" title="Memory Allocators"><meta name="generator" content="GTK-Doc V1.4 (XML mode)"><link rel="stylesheet" href="style.css" type="text/css"><link rel="chapter" href="glib.html" title="GLib Overview"><link rel="chapter" href="glib-fundamentals.html" title="GLib Fundamentals"><link rel="chapter" href="glib-core.html" title="GLib Core Application Support"><link rel="chapter" href="glib-utilities.html" title="GLib Utilities"><link rel="chapter" href="glib-data-types.html" title="GLib Data Types"><link rel="chapter" href="tools.html" title="GLib Tools"><link rel="index" href="ix01.html" title="Index"><link rel="index" href="ix02.html" title="Index of deprecated symbols"><link rel="index" href="ix03.html" title="Index of new symbols in 2.2"><link rel="index" href="ix04.html" title="Index of new symbols in 2.4"><link rel="index" href="ix05.html" title="Index of new symbols in 2.6"></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-Relations-and-Tuples.html"><img src="left.png" width="24" height="24" border="0" alt="Prev"></a></td><td><a accesskey="u" href="glib-data-types.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-Memory-Allocators.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-Caches"></a><div class="titlepage"></div><div class="refnamediv"><table width="100%"><tr><td valign="top"><h2><span class="refentrytitle">Caches</span></h2><p>Caches &#8212; caches allow sharing of complex data structures to save resources.</p></td><td valign="top" align="right"></td></tr></table></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">#include &lt;glib.h&gt;            <a href="glib-Caches.html#GCache">GCache</a>;<a href="glib-Caches.html#GCache">GCache</a>*     <a href="glib-Caches.html#g-cache-new">g_cache_new</a>                     (<a href="glib-Caches.html#GCacheNewFunc">GCacheNewFunc</a> value_new_func,                                             <a href="glib-Caches.html#GCacheDestroyFunc">GCacheDestroyFunc</a> value_destroy_func,                                             <a href="glib-Caches.html#GCacheDupFunc">GCacheDupFunc</a> key_dup_func,                                             <a href="glib-Caches.html#GCacheDestroyFunc">GCacheDestroyFunc</a> key_destroy_func,                                             <a href="glib-Hash-Tables.html#GHashFunc">GHashFunc</a> hash_key_func,                                             <a href="glib-Hash-Tables.html#GHashFunc">GHashFunc</a> hash_value_func,                                             <a href="glib-Hash-Tables.html#GEqualFunc">GEqualFunc</a> key_equal_func);<a href="glib-Basic-Types.html#gpointer">gpointer</a>    <a href="glib-Caches.html#g-cache-insert">g_cache_insert</a>                  (<a href="glib-Caches.html#GCache">GCache</a> *cache,                                             <a href="glib-Basic-Types.html#gpointer">gpointer</a> key);void        <a href="glib-Caches.html#g-cache-remove">g_cache_remove</a>                  (<a href="glib-Caches.html#GCache">GCache</a> *cache,                                             <a href="glib-Basic-Types.html#gconstpointer">gconstpointer</a> value);void        <a href="glib-Caches.html#g-cache-destroy">g_cache_destroy</a>                 (<a href="glib-Caches.html#GCache">GCache</a> *cache);void        <a href="glib-Caches.html#g-cache-key-foreach">g_cache_key_foreach</a>             (<a href="glib-Caches.html#GCache">GCache</a> *cache,                                             <a href="glib-Hash-Tables.html#GHFunc">GHFunc</a> func,                                             <a href="glib-Basic-Types.html#gpointer">gpointer</a> user_data);void        <a href="glib-Caches.html#g-cache-value-foreach">g_cache_value_foreach</a>           (<a href="glib-Caches.html#GCache">GCache</a> *cache,                                             <a href="glib-Hash-Tables.html#GHFunc">GHFunc</a> func,                                             <a href="glib-Basic-Types.html#gpointer">gpointer</a> user_data);void        (<a href="glib-Caches.html#GCacheDestroyFunc">*GCacheDestroyFunc</a>)            (<a href="glib-Basic-Types.html#gpointer">gpointer</a> value);<a href="glib-Basic-Types.html#gpointer">gpointer</a>    (<a href="glib-Caches.html#GCacheDupFunc">*GCacheDupFunc</a>)                (<a href="glib-Basic-Types.html#gpointer">gpointer</a> value);<a href="glib-Basic-Types.html#gpointer">gpointer</a>    (<a href="glib-Caches.html#GCacheNewFunc">*GCacheNewFunc</a>)                (<a href="glib-Basic-Types.html#gpointer">gpointer</a> key);</pre></div><div class="refsect1" lang="en"><a name="id3203004"></a><h2>Description</h2><p>A <a href="glib-Caches.html#GCache"><span class="type">GCache</span></a> allows sharing of complex data structures, in order to savesystem resources.</p><p>GTK+ uses caches for <span class="type">GtkStyles</span> and <span class="type">GdkGCs</span>. These consume a lot ofresources, so a <a href="glib-Caches.html#GCache"><span class="type">GCache</span></a> is used to see if a <ahref="../gtk/GtkStyle.html"><span class="type">GtkStyle</span></a> or <ahref="../gdk/gdk-Graphics-Contexts.html#GdkGC"><span class="type">GdkGC</span></a> with therequired properties already exists. If it does, then the existingobject is used instead of creating a new one.</p><p><a href="glib-Caches.html#GCache"><span class="type">GCache</span></a> uses keys and values.A <a href="glib-Caches.html#GCache"><span class="type">GCache</span></a> key describes the properties of a particular resource.A <a href="glib-Caches.html#GCache"><span class="type">GCache</span></a> value is the actual resource.</p></div><div class="refsect1" lang="en"><a name="id3203103"></a><h2>Details</h2><div class="refsect2" lang="en"><a name="id3203108"></a><h3><a name="GCache"></a>GCache</h3><a class="indexterm" name="id3203118"></a><pre class="programlisting">typedef struct _GCache GCache;</pre><p>The <a href="glib-Caches.html#GCache"><span class="type">GCache</span></a> struct is an opaque data structure containing information abouta <a href="glib-Caches.html#GCache"><span class="type">GCache</span></a>. It should only be accessed via the following functions.</p></div><hr><div class="refsect2" lang="en"><a name="id3203152"></a><h3><a name="g-cache-new"></a>g_cache_new ()</h3><a class="indexterm" name="id3203162"></a><pre class="programlisting"><a href="glib-Caches.html#GCache">GCache</a>*     g_cache_new                     (<a href="glib-Caches.html#GCacheNewFunc">GCacheNewFunc</a> value_new_func,                                             <a href="glib-Caches.html#GCacheDestroyFunc">GCacheDestroyFunc</a> value_destroy_func,                                             <a href="glib-Caches.html#GCacheDupFunc">GCacheDupFunc</a> key_dup_func,                                             <a href="glib-Caches.html#GCacheDestroyFunc">GCacheDestroyFunc</a> key_destroy_func,                                             <a href="glib-Hash-Tables.html#GHashFunc">GHashFunc</a> hash_key_func,                                             <a href="glib-Hash-Tables.html#GHashFunc">GHashFunc</a> hash_value_func,                                             <a href="glib-Hash-Tables.html#GEqualFunc">GEqualFunc</a> key_equal_func);</pre><p>Creates a new <a href="glib-Caches.html#GCache"><span class="type">GCache</span></a>.</p><div class="variablelist"><table border="0"><col align="left" valign="top"><tbody><tr><td><span class="term"><em class="parameter"><code>value_new_func</code></em>&#160;:</span></td><td>a function to create a new object given a key.This is called by <a href="glib-Caches.html#g-cache-insert"><code class="function">g_cache_insert()</code></a> if an object with the given keydoes not already exist.</td></tr><tr><td><span class="term"><em class="parameter"><code>value_destroy_func</code></em>&#160;:</span></td><td>a function to destroy an object. It iscalled by <a href="glib-Caches.html#g-cache-remove"><code class="function">g_cache_remove()</code></a> when the object is no longer needed (i.e. itsreference count drops to 0).</td></tr><tr><td><span class="term"><em class="parameter"><code>key_dup_func</code></em>&#160;:</span></td><td>a function to copy a key. It is called by<a href="glib-Caches.html#g-cache-insert"><code class="function">g_cache_insert()</code></a> if the key does not already exist in the <a href="glib-Caches.html#GCache"><span class="type">GCache</span></a>.</td></tr><tr><td><span class="term"><em class="parameter"><code>key_destroy_func</code></em>&#160;:</span></td><td>a function to destroy a key. It iscalled by <a href="glib-Caches.html#g-cache-remove"><code class="function">g_cache_remove()</code></a> when the object is no longer needed (i.e. itsreference count drops to 0).</td></tr><tr><td><span class="term"><em class="parameter"><code>hash_key_func</code></em>&#160;:</span></td><td>a function to create a hash value from a key.</td></tr><tr><td><span class="term"><em class="parameter"><code>hash_value_func</code></em>&#160;:</span></td><td>a function to create a hash value from a value.</td></tr><tr><td><span class="term"><em class="parameter"><code>key_equal_func</code></em>&#160;:</span></td><td>a function to compare two keys. It should return <code class="literal">TRUE</code> ifthe two keys are equivalent.</td></tr><tr><td><span class="term"><span class="emphasis"><em>Returns</em></span>&#160;:</span></td><td>a new <a href="glib-Caches.html#GCache"><span class="type">GCache</span></a>.</td></tr></tbody></table></div></div><hr><div class="refsect2" lang="en"><a name="id3203432"></a><h3><a name="g-cache-insert"></a>g_cache_insert ()</h3><a class="indexterm" name="id3203442"></a><pre class="programlisting"><a href="glib-Basic-Types.html#gpointer">gpointer</a>    g_cache_insert                  (<a href="glib-Caches.html#GCache">GCache</a> *cache,                                             <a href="glib-Basic-Types.html#gpointer">gpointer</a> key);</pre><p>Gets the value corresponding to the given key, creating it if necessary.It first checks if the value already exists in the <a href="glib-Caches.html#GCache"><span class="type">GCache</span></a>, by usingthe <em class="parameter"><code>key_equal_func</code></em> function passed to <a href="glib-Caches.html#g-cache-new"><code class="function">g_cache_new()</code></a>.If it does already exist it is returned, and its reference count is increasedby one.If the value does not currently exist, if is created by calling the<em class="parameter"><code>value_new_func</code></em>. The key is duplicated by calling<em class="parameter"><code>key_dup_func</code></em> and the duplicated key and value are insertedinto the <a href="glib-Caches.html#GCache"><span class="type">GCache</span></a>.</p><div class="variablelist"><table border="0"><col align="left" valign="top"><tbody><tr><td><span class="term"><em class="parameter"><code>cache</code></em>&#160;:</span></td><td>a <a href="glib-Caches.html#GCache"><span class="type">GCache</span></a>.</td></tr><tr><td><span class="term"><em class="parameter"><code>key</code></em>&#160;:</span></td><td>a key describing a <a href="glib-Caches.html#GCache"><span class="type">GCache</span></a> object.</td></tr><tr><td><span class="term"><span class="emphasis"><em>Returns</em></span>&#160;:</span></td><td>a pointer to a <a href="glib-Caches.html#GCache"><span class="type">GCache</span></a> value.</td>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -