The Cache Class
[The Classes]

A cache to share objects. More...


Modules

 The Cache Interface

Typedefs

typedef Cmaid_Container Cmaid_Cache
 Type definition of the Cache Class.

Functions

CMAID_INLINE void * cmaid_cache_instance (Cmaid_Cache *s, const void *data)
 Caches an object for reuse.
CMAID_INLINE void cmaid_cache_release (Cmaid_Cache *s, const void *data)
 Decrease the reference count of the given object.


Detailed Description

A cache to share objects.

The cache class provides an interface to reuse objects to reduce overall memory usage. The cache is intended to be used for (large) constant arrays or structures that are used in many place at the same time. Instead of having an allocated copy of the object, the cache gives the opportunity to share them, and to have only one copy of them. This can reduce the overall memory usage. Keep in mind that this only works if the objects are not unique.

Since the cache interface is inheriting from the container interface, you can use all available container functions for it to.

Note:
Only use the cmaid_iter_remove() if you really know what you are doing, because it will remove the object completely from the cache.

Function Documentation

CMAID_INLINE void* cmaid_cache_instance ( Cmaid_Cache s,
const void *  data 
)

Caches an object for reuse.

Parameters:
s The cache to get an instance
data The object to cache
Returns:
Returns the reference of the cached object The cache will return the address of the data that is already cached and increase the internal object reference count. If there is not a matching object inside of the cache, a new one will be created and returned.

CMAID_INLINE void cmaid_cache_release ( Cmaid_Cache s,
const void *  data 
)

Decrease the reference count of the given object.

Parameters:
s The cache to release an instance
data The object to be released
Returns:
Returns no value The cache will decrease the reference of the given object. If the object is not used else where, the object will be destroyed. Do not use the object reference after this, because you cannot be sure if it is still a legal address.


Generated on Wed Aug 5 00:20:49 2009 for Cmaid by  doxygen 1.5.8