Mitsuba Renderer  0.5.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
mitsuba::SimpleCache< ArgType, ReturnType > Class Template Reference

Generic thread-local storage for caching evaluations of expensive function calls. More...

#include <mitsuba/core/simplecache.h>

+ Inheritance diagram for mitsuba::SimpleCache< ArgType, ReturnType >:

Public Member Functions

 SimpleCache ()
 
template<typename UpdateFunctor >
ReturnType & get (const UpdateFunctor &functor, const ArgType &argument)
 Return the cache entry for the argument argument or run UpdateFunctor to compute it. More...
 

Protected Types

typedef std::pair< ArgType,
ReturnType > 
ValueType
 
typedef PrimitiveThreadLocal
< ValueType
ParentType
 

Additional Inherited Members

- Protected Member Functions inherited from mitsuba::PrimitiveThreadLocal< std::pair< ArgType, ReturnType > >
 PrimitiveThreadLocal ()
 Construct a new thread local storage object. More...
 
void set (std::pair< ArgType, ReturnType > &value)
 Update the data associated with the current thread. More...
 
std::pair< ArgType, ReturnType > & get ()
 Return a reference to the data associated with the current thread. More...
 
const std::pair< ArgType,
ReturnType > & 
get () const
 Return a reference to the data associated with the current thread (const version) More...
 
- Static Protected Member Functions inherited from mitsuba::PrimitiveThreadLocal< std::pair< ArgType, ReturnType > >
static void * construct ()
 
static void destruct (void *data)
 
- Protected Attributes inherited from mitsuba::PrimitiveThreadLocal< std::pair< ArgType, ReturnType > >
detail::ThreadLocalBase m_base
 

Detailed Description

template<typename ArgType, typename ReturnType>
class mitsuba::SimpleCache< ArgType, ReturnType >

Generic thread-local storage for caching evaluations of expensive function calls.

This class implements a simple and efficient one-entry storage for caching the result of a call to an expensive-to-evaluate function that has no side effects.

The target application is a situation where multiple threads are causing calls to such a function and each individual thread may invoke it a few times in a row using the same input argument.

This storage class provides the means to avoid re-evaluating the function in this case. By isolating threads from one another, it does not suffer heavy costs for inter-thread synchronizations.

Here is an example snippet:

struct MyFunctor {
inline void operator()(const Point &input, Float &output) {
// .... Perform expensive function call / computation .....
}
};
void test() {
SimpleCache<Point, Float> myCache;
MyFunctor functor;
// First call -- evaluate the functor for the given input
Float result = myCache.get(functor, Point(1,2,3));
// Now, the evaluation can uses the cached value
Float result2 = myCache.get(functor, Point(1,2,3));
}
Template Parameters
ArgTypeArgument type of the function whose return values should be cached
ReturnTypeReturn type of the function whose return values should be cached

Member Typedef Documentation

template<typename ArgType, typename ReturnType>
typedef PrimitiveThreadLocal<ValueType> mitsuba::SimpleCache< ArgType, ReturnType >::ParentType
protected
template<typename ArgType, typename ReturnType>
typedef std::pair<ArgType, ReturnType> mitsuba::SimpleCache< ArgType, ReturnType >::ValueType
protected

Constructor & Destructor Documentation

template<typename ArgType, typename ReturnType>
mitsuba::SimpleCache< ArgType, ReturnType >::SimpleCache ( )
inline

Member Function Documentation

template<typename ArgType, typename ReturnType>
template<typename UpdateFunctor >
ReturnType& mitsuba::SimpleCache< ArgType, ReturnType >::get ( const UpdateFunctor &  functor,
const ArgType &  argument 
)
inline

Return the cache entry for the argument argument or run UpdateFunctor to compute it.


The documentation for this class was generated from the following file: