Implements an LRU-Caching Strategy for arbitrary Cache-Lines. More...
#include <shark/LinAlg/LRUCache.h>
Public Member Functions | |
LRUCache (std::size_t lines, std::size_t cachesize=0x4000000) | |
Creates a cache with a given maximum index "lines" and a given maximum cache size. More... | |
~LRUCache () | |
bool | isCached (std::size_t i) const |
Returns true if the line is cached. More... | |
std::size_t | lineLength (std::size_t i) const |
Returns the size of the cached line. More... | |
std::size_t | cachedLines () const |
Returns the number of lines currently allocated. More... | |
T * | getCacheLine (std::size_t i, std::size_t size) |
Returns the line with index i with the correct size. More... | |
T * | getLinePointer (std::size_t i) |
Just returns the pointer to the i-th line without affcting cache at all. More... | |
T const * | getLinePointer (std::size_t i) const |
Just returns the pointer to the i-th line without affcting cache at all. More... | |
void | resizeLine (std::size_t i, std::size_t size) |
Resizes a line while retaining the data stored inside it. More... | |
void | markLineForDeletion (std::size_t i) |
Marks cache line i for deletion, that is the next time memory is needed, this line will be freed. More... | |
void | swapLineIndices (std::size_t i, std::size_t j) |
swaps index of lines i and j. More... | |
std::size_t | size () const |
std::size_t | listIndex (std::size_t i) const |
std::size_t | maxSize () const |
void | clear () |
empty cache More... | |
Implements an LRU-Caching Strategy for arbitrary Cache-Lines.
Low Level Cache which stores cache lines, arrays of T[size] where size is a variable length for every cache line. Every line is associated with some index 0<i < max. It is assumed that not all cache lines can be stored at the same time, but only a (small) subset. The size of the cache is bounded by the summed length of all cache lines, that means that when the lines are very short, the cache can store more lines. If the cache is full and another line needs to be accessed, or an existing line needs to be resized, cache lines need to be freed. This cache uses an Least-Recently-Used strategy. The cache maintains a list. Everytime a cacheline is accessed, it moves to the front of the list. When a line is freed the end of the list is chosen.
Definition at line 55 of file LRUCache.h.
|
inline |
Creates a cache with a given maximum index "lines" and a given maximum cache size.
Definition at line 65 of file LRUCache.h.
|
inline |
Definition at line 70 of file LRUCache.h.
|
inline |
Returns the number of lines currently allocated.
Definition at line 84 of file LRUCache.h.
|
inline |
empty cache
Definition at line 197 of file LRUCache.h.
Referenced by shark::CachedMatrix< Matrix >::clear(), and shark::LRUCache< QpFloatType >::~LRUCache().
|
inline |
Returns the line with index i with the correct size.
If the line is not cached, it is created with the exact size. if it is cached and is at least as big, it is returned unchanged. otherwise it is resized to the proper size and the old values are kept.
Definition at line 93 of file LRUCache.h.
Referenced by shark::CachedMatrix< Matrix >::row().
|
inline |
Just returns the pointer to the i-th line without affcting cache at all.
Definition at line 108 of file LRUCache.h.
Referenced by shark::CachedMatrix< Matrix >::flipColumnsAndRows(), and shark::CachedMatrix< Matrix >::row().
|
inline |
Just returns the pointer to the i-th line without affcting cache at all.
Definition at line 113 of file LRUCache.h.
|
inline |
Returns true if the line is cached.
Definition at line 75 of file LRUCache.h.
Referenced by shark::LRUCache< QpFloatType >::getCacheLine(), shark::CachedMatrix< Matrix >::isCached(), shark::LRUCache< QpFloatType >::markLineForDeletion(), and shark::LRUCache< QpFloatType >::swapLineIndices().
|
inline |
Returns the size of the cached line.
Definition at line 79 of file LRUCache.h.
Referenced by shark::CachedMatrix< Matrix >::flipColumnsAndRows(), shark::CachedMatrix< Matrix >::getCacheRowSize(), and shark::CachedMatrix< Matrix >::row().
|
inline |
Definition at line 187 of file LRUCache.h.
|
inline |
Marks cache line i for deletion, that is the next time memory is needed, this line will be freed.
Definition at line 125 of file LRUCache.h.
Referenced by shark::CachedMatrix< Matrix >::setMaxCachedIndex().
|
inline |
Definition at line 192 of file LRUCache.h.
Referenced by shark::CachedMatrix< Matrix >::getMaxCacheSize().
|
inline |
Resizes a line while retaining the data stored inside it.
if the new size is smaller than the old, only the first size entries are saved.
Definition at line 120 of file LRUCache.h.
Referenced by shark::LRUCache< QpFloatType >::clear(), shark::LRUCache< QpFloatType >::getCacheLine(), and shark::LRUCache< QpFloatType >::resizeLine().
|
inline |
Definition at line 183 of file LRUCache.h.
Referenced by shark::LRUCache< QpFloatType >::clear(), and shark::CachedMatrix< Matrix >::getCacheSize().
|
inline |
swaps index of lines i and j.
Definition at line 133 of file LRUCache.h.
Referenced by shark::CachedMatrix< Matrix >::flipColumnsAndRows().