1 <!-- ##### SECTION Title ##### -->
4 <!-- ##### SECTION Short_Description ##### -->
5 caches allow sharing of complex data structures to save resources.
7 <!-- ##### SECTION Long_Description ##### -->
9 A #GCache allows sharing of complex data structures, in order to save
13 GTK+ uses caches for #GtkStyles and #GdkGCs. These consume a lot of
14 resources, 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 object is used instead of creating a new one.
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.
24 <!-- ##### SECTION See_Also ##### -->
29 <!-- ##### SECTION Stability_Level ##### -->
32 <!-- ##### STRUCT GCache ##### -->
34 The #GCache struct is an opaque data structure containing information about
35 a #GCache. It should only be accessed via the following functions.
39 <!-- ##### FUNCTION g_cache_new ##### -->
41 Creates a new #GCache.
44 @value_new_func: a function to create a new object given a key.
45 This is called by g_cache_insert() if an object with the given key
46 does not already exist.
47 @value_destroy_func: a function to destroy an object. It is
48 called by g_cache_remove() when the object is no longer needed (i.e. its
49 reference count drops to 0).
50 @key_dup_func: a function to copy a key. It is called by
51 g_cache_insert() if the key does not already exist in the #GCache.
52 @key_destroy_func: a function to destroy a key. It is
53 called by g_cache_remove() when the object is no longer needed (i.e. its
54 reference count drops to 0).
55 @hash_key_func: a function to create a hash value from a key.
56 @hash_value_func: a function to create a hash value from a value.
57 @key_equal_func: a function to compare two keys. It should return %TRUE if
58 the two keys are equivalent.
59 @Returns: a new #GCache.
62 <!-- ##### FUNCTION g_cache_insert ##### -->
64 Gets the value corresponding to the given key, creating it if necessary.
65 It first checks if the value already exists in the #GCache, by using
66 the @key_equal_func function passed to g_cache_new().
67 If it does already exist it is returned, and its reference count is increased
69 If the value does not currently exist, if is created by calling the
70 @value_new_func. The key is duplicated by calling
71 @key_dup_func and the duplicated key and value are inserted
76 @key: a key describing a #GCache object.
77 @Returns: a pointer to a #GCache value.
80 <!-- ##### FUNCTION g_cache_remove ##### -->
82 Decreases the reference count of the given value.
83 If it drops to 0 then the value and its corresponding key are destroyed,
84 using the @value_destroy_func and @key_destroy_func passed to g_cache_new().
88 @value: the value to remove.
91 <!-- ##### FUNCTION g_cache_destroy ##### -->
93 Frees the memory allocated for the #GCache.
96 Note that it does not destroy the keys and values which were contained in the
103 <!-- ##### FUNCTION g_cache_key_foreach ##### -->
105 Calls the given function for each of the keys in the #GCache.
109 @func: the function to call with each #GCache key.
110 @user_data: user data to pass to the function.
113 <!-- ##### FUNCTION g_cache_value_foreach ##### -->
115 Calls the given function for each of the values in the #GCache.
119 @func: the function to call with each #GCache value.
120 @user_data: user data to pass to the function.
123 <!-- ##### USER_FUNCTION GCacheDestroyFunc ##### -->
125 Specifies the type of the @value_destroy_func and @key_destroy_func functions
126 passed to g_cache_new().
127 The functions are passed a pointer to the #GCache key or #GCache value and
128 should free any memory and other resources associated with it.
131 @value: the #GCache value to destroy.
134 <!-- ##### USER_FUNCTION GCacheDupFunc ##### -->
136 Specifies the type of the @key_dup_func function passed to g_cache_new().
137 The function is passed a key (<emphasis>not</emphasis> a value as the prototype implies) and
138 should return a duplicate of the key.
141 @value: the #GCache key to destroy (<emphasis>not</emphasis> a #GCache value as it seems).
142 @Returns: a copy of the #GCache key.
145 <!-- ##### USER_FUNCTION GCacheNewFunc ##### -->
147 Specifies the type of the @value_new_func function passed to g_cache_new().
148 It is passed a #GCache key and should create the value corresponding to the
153 @Returns: a new #GCache value corresponding to the key.