开发者

What is the "cached function" referring to in this code article?

In relation to this article: http://www.bottlenose.demon.co.uk/article/lru.htm

What is the cached function he is referring to?

I am thinking of using it but I do not understand w开发者_Go百科hat the purpose of that function is and I could not figure out the test code. I'm not familiar with boost test.

An example of simple use would have been good.


It's just a function that you provide when you construct the object. The object's purpose is to cache the result of calling the function.

So if the function is expensive to compute, but you tend to call it over and over with the same input, the expensive computation will run once and later invocations can access the cache.

This technique is called "memoization" or "dynamic programming" and is often a handy way to speed up an otherwise exponential-time recursive algorithm.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜