fixed dealing with collection/lcopy of NULL values.
[platform/upstream/glib.git] / docs / reference / glib / tmpl / caches.sgml
1 <!-- ##### SECTION Title ##### -->
2 Caches
3
4 <!-- ##### SECTION Short_Description ##### -->
5 allows sharing of complex data structures to save resources.
6
7 <!-- ##### SECTION Long_Description ##### -->
8 <para>
9 A #GCache allows sharing of complex data structures, in order to save
10 system resources.
11 </para>
12 <para>
13 GTK uses a #GCache for both GtkStyles and GdkGCs. These consume a lot of
14 resouces, so a #GCache is used to see if a GtkStyle or GdkGC with the
15 required properties already exists. If it does, then the existing
16 GtkStyle or GdkGC is used instead of creating a new one.
17 </para>
18 <para>
19 #GCache uses keys and values.
20 A #GCache key describes the properties of a particular resource.
21 A #GCache value is the actual resource.
22 </para>
23
24 <!-- ##### SECTION See_Also ##### -->
25 <para>
26
27 </para>
28
29 <!-- ##### STRUCT GCache ##### -->
30 <para>
31 The #GCache struct is an opaque data structure containing information about
32 a #GCache. It should only be accesssed via the following functions.
33 </para>
34
35
36 <!-- ##### FUNCTION g_cache_new ##### -->
37 <para>
38 Creates a new GCache.
39 </para>
40
41 @value_new_func: a function to create a new object given a key.
42 This is called by g_cache_insert() if an object with the given key
43 does not already exist.
44 @value_destroy_func: a function to destroy an object. It is
45 called by g_cache_remove() when the object is no longer needed (i.e. its
46 reference count drops to 0).
47 @key_dup_func: a function to copy a key. It is called by
48 g_cache_insert() if the key does not already exist in the GCache.
49 @key_destroy_func: a function to destroy a key. It is
50 called by g_cache_remove() when the object is no longer needed (i.e. its
51 reference count drops to 0).
52 @hash_key_func: a function to create a hash value from a key.
53 @hash_value_func: a function to create a hash value from a value.
54 @key_compare_func: 
55 @Returns: a new #GCache.
56 <!-- # Unused Parameters # -->
57 @key_equal_func: a function to compare two keys. It should return TRUE if
58 the two keys are equivalent.
59
60
61 <!-- ##### FUNCTION g_cache_insert ##### -->
62 <para>
63 Gets the value corresponding to the given key, creating it if necessary.
64 It first checks if the value already exists in the #GCache, by using
65 the @key_equal_func function passed to g_cache_new().
66 If it does already exist it is returned, and its reference count is increased
67 by one.
68 If the value does not currently exist, if is created by calling the
69 @value_new_func. The key is duplicated by calling
70 @key_dup_func and the duplicated key and value are inserted
71 into the #GCache.
72 </para>
73
74 @cache: a #GCache.
75 @key: a key describing a #GCache object.
76 @Returns: a pointer to a #GCache value.
77
78
79 <!-- ##### FUNCTION g_cache_remove ##### -->
80 <para>
81 Decreases the reference count of the given value.
82 If it drops to 0 then the value and its corresponding key are destroyed,
83 using the @value_destroy_func and @key_destroy_func passed to g_cache_new().
84 </para>
85
86 @cache: a #GCache.
87 @value: the value to remove.
88
89
90 <!-- ##### FUNCTION g_cache_destroy ##### -->
91 <para>
92 Frees the memory allocated for the GCache.
93 </para>
94 <para>
95 Note that it does not destroy the keys and values which were contained in the
96 GCache.
97 </para>
98
99 @cache: 
100
101
102 <!-- ##### FUNCTION g_cache_key_foreach ##### -->
103 <para>
104 Calls the given function for each of the keys in the #GCache.
105 </para>
106
107 @cache: a #GCache.
108 @func: the function to call with each #GCache key.
109 @user_data: user data to pass to the function.
110
111
112 <!-- ##### FUNCTION g_cache_value_foreach ##### -->
113 <para>
114 Calls the given function for each of the values in the #GCache.
115 </para>
116
117 @cache: a #GCache.
118 @func: the function to call with each #GCache value.
119 @user_data: user data to pass to the function.
120
121
122 <!-- ##### USER_FUNCTION GCacheDestroyFunc ##### -->
123 <para>
124 Specifies the type of the @value_destroy_func and @key_destroy_func functions
125 passed to g_cache_new().
126 The functions are passed a pointer to the #GCache key or #GCache value and
127 should free any memory and other resources associated with it.
128 </para>
129
130 @value: the #GCache value to destroy.
131
132
133 <!-- ##### USER_FUNCTION GCacheDupFunc ##### -->
134 <para>
135 Specifies the type of the @key_dup_func function passed to g_cache_new().
136 The function is passed a key (NOT a value as the prototype implies) and
137 should return a duplicate of the key.
138 </para>
139
140 @value: the #GCache key to destroy (NOT a #GCache value as it seems).
141 @Returns: a copy of the #GCache key.
142
143
144 <!-- ##### USER_FUNCTION GCacheNewFunc ##### -->
145 <para>
146 Specifies the type of the @value_new_func function passed to g_cache_new().
147 It is passed a #GCache key and should create the value corresponding to the
148 key.
149 </para>
150
151 @key: a #GCache key.
152 @Returns: a new #GCache value corresponding to the key.
153
154