1 <!-- ##### SECTION Title ##### -->
4 <!-- ##### SECTION Short_Description ##### -->
5 allows 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 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.
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 <!-- ##### STRUCT GCache ##### -->
31 The #GCache struct is an opaque data structure containing information about
32 a #GCache. It should only be accesssed via the following functions.
36 <!-- ##### FUNCTION g_cache_new ##### -->
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.
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.
61 <!-- ##### FUNCTION g_cache_insert ##### -->
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
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
75 @key: a key describing a #GCache object.
76 @Returns: a pointer to a #GCache value.
79 <!-- ##### FUNCTION g_cache_remove ##### -->
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().
87 @value: the value to remove.
90 <!-- ##### FUNCTION g_cache_destroy ##### -->
92 Frees the memory allocated for the GCache.
95 Note that it does not destroy the keys and values which were contained in the
102 <!-- ##### FUNCTION g_cache_key_foreach ##### -->
104 Calls the given function for each of the keys in the #GCache.
108 @func: the function to call with each #GCache key.
109 @user_data: user data to pass to the function.
112 <!-- ##### FUNCTION g_cache_value_foreach ##### -->
114 Calls the given function for each of the values in the #GCache.
118 @func: the function to call with each #GCache value.
119 @user_data: user data to pass to the function.
122 <!-- ##### USER_FUNCTION GCacheDestroyFunc ##### -->
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.
130 @value: the #GCache value to destroy.
133 <!-- ##### USER_FUNCTION GCacheDupFunc ##### -->
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.
140 @value: the #GCache key to destroy (NOT a #GCache value as it seems).
141 @Returns: a copy of the #GCache key.
144 <!-- ##### USER_FUNCTION GCacheNewFunc ##### -->
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
152 @Returns: a new #GCache value corresponding to the key.