|
mlt 0.7.6
|
Cache class. More...
Public Member Functions | |
| void | mlt_cache_close (mlt_cache cache) |
| Destroy a cache. | |
| mlt_cache_item | mlt_cache_get (mlt_cache cache, void *object) |
| Get a chunk of data from the cache. | |
| int | mlt_cache_get_size (mlt_cache cache) |
| Get the numer of possible cache items. | |
| mlt_cache | mlt_cache_init () |
| Create a new cache. | |
| void * | mlt_cache_item_data (mlt_cache_item item, int *size) |
| Get the data pointer from the cache item. | |
| void | mlt_cache_purge (mlt_cache cache, void *object) |
| Remove cache entries for an object. | |
| void | mlt_cache_put (mlt_cache cache, void *object, void *data, int size, mlt_destructor destructor) |
| Put a chunk of data in the cache. | |
| void | mlt_cache_set_size (mlt_cache cache, int size) |
| Set the numer of items to cache. | |
Data Fields | |
| void * | A [MAX_CACHE_SIZE] |
| mlt_properties | active |
a list of cache items some of which may no longer be in current but to which there are outstanding references | |
| void * | B [MAX_CACHE_SIZE] |
| int | count |
| the number of items currently in the cache | |
| void * | current |
| pointer to the current array of pointers | |
| mlt_properties | garbage |
| a list cache items pending release. | |
| pthread_mutex_t | mutex |
| a mutex to prevent multi-threaded race conditions | |
| int | size |
the maximum number of items permitted in the cache <= MAX_CACHE_SIZE | |
Private Member Functions | |
| static void | cache_object_close (mlt_cache cache, void *object, void *data) |
| Close a cache item given its parent object pointer. | |
| static void ** | shuffle_get_hit (mlt_cache cache, void *object) |
| Shuffle the cache entries between the two arrays and return the cache entry for an object. | |
Cache class.
This is a utility class for implementing a Least Recently Used (LRU) cache of data blobs indexed by the address of some other object (e.g., a service). Instead of sorting and manipulating linked lists, it tries to be simple and elegant by copying pointers between two arrays of fixed size to shuffle the order of elements.
This class is useful if you have a service that wants to cache something somewhat large, but will not scale if there are many instances of the service. Of course, the service will need to know how to recreate the cached element if it gets flushed from the cache,
The most obvious examples are the pixbuf and qimage producers that cache their respective objects representing a picture read from a file. If the picture is no longer in the cache, it can simply re-read it from file. However, a picture is often repeated over many frames and makes sense to cache instead of continually reading, parsing, and decoding. On the other hand, you might want to load hundreds of pictures as individual producers, which would use a lot of memory if every picture is held in memory!
| static void cache_object_close | ( | mlt_cache | cache, |
| void * | object, | ||
| void * | data | ||
| ) | [private] |
Close a cache item given its parent object pointer.
| cache | a cache |
| object | the object to which the data object belongs |
| data | the data object, which might be in the garbage list (optional) |
| void mlt_cache_close | ( | mlt_cache | cache | ) |
Destroy a cache.
| cache | the cache to destroy |
| mlt_cache_item mlt_cache_get | ( | mlt_cache | cache, |
| void * | object | ||
| ) |
Get a chunk of data from the cache.
| cache | a cache object |
| object | the object for which you are trying to locate the data |
| int mlt_cache_get_size | ( | mlt_cache | cache | ) |
Get the numer of possible cache items.
| cache | the cache to check |
| mlt_cache mlt_cache_init | ( | ) |
Create a new cache.
The default size is DEFAULT_CACHE_SIZE.
| void * mlt_cache_item_data | ( | mlt_cache_item | item, |
| int * | size | ||
| ) |
Get the data pointer from the cache item.
| item | a cache item | |
| [out] | size | the number of bytes pointed at, if supplied when putting the data into the cache |
| void mlt_cache_purge | ( | mlt_cache | cache, |
| void * | object | ||
| ) |
Remove cache entries for an object.
| cache | a cache |
| object | the object that owns the cached data |
| void mlt_cache_put | ( | mlt_cache | cache, |
| void * | object, | ||
| void * | data, | ||
| int | size, | ||
| mlt_destructor | destructor | ||
| ) |
Put a chunk of data in the cache.
| cache | a cache object |
| object | the object to which this data belongs |
| data | an opaque pointer to the data to cache |
| size | the size of the data in bytes |
| destructor | a pointer to a function that can destroy or release a reference to the data. |
| void mlt_cache_set_size | ( | mlt_cache | cache, |
| int | size | ||
| ) |
Set the numer of items to cache.
This must be called before using the cache. The size can not be more than MAX_CACHE_SIZE.
| cache | the cache to adjust |
| size | the new size of the cache |
| static void ** shuffle_get_hit | ( | mlt_cache | cache, |
| void * | object | ||
| ) | [private] |
Shuffle the cache entries between the two arrays and return the cache entry for an object.
| cache | a cache object |
| object | the object that owns the cached data |
| void* mlt_cache_s::A[MAX_CACHE_SIZE] |
a list of cache items some of which may no longer be in current but to which there are outstanding references
| void* mlt_cache_s::B[MAX_CACHE_SIZE] |
the number of items currently in the cache
| void* mlt_cache_s::current |
pointer to the current array of pointers
a list cache items pending release.
A cache item is copied to this list when it is updated but there are outstanding references to the old data object.
| pthread_mutex_t mlt_cache_s::mutex |
a mutex to prevent multi-threaded race conditions
the maximum number of items permitted in the cache <= MAX_CACHE_SIZE
1.7.3