Generic thread-local storage for caching evaluations of expensive function calls.
More...
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) {
}
};
void test() {
SimpleCache<Point, Float> myCache;
MyFunctor functor;
Float result = myCache.get(functor,
Point(1,2,3));
Float result2 = myCache.get(functor,
Point(1,2,3));
}
- Template Parameters
-
ArgType | Argument type of the function whose return values should be cached |
ReturnType | Return type of the function whose return values should be cached |