I am writing a manual computation memoization system (ugh, in Matlab). The straightforward parts are easy:
- A way to put data into the memoization system after performing a computation.
- A way to query and get data out of the memoization.
- A way to query the system for all the 'keys'.
These parts are not so much in doubt. The problem is that my computer has a finite amount of memory, so sometime the 'put' operation will have to dump some objects out of memory. I am worried about 'cache misses', so I would like some relatively simple system for dropping the memoized objects which are not used frequently and/or are not costly to recompute. How do I design that system? The parts I can imagine it having:
- A way to tell the 'put' operation how costly (relatively speaking) the computation was.
- A way to optionally hint to the 'put' operation how often the computation might be needed (going forward).
- The 'get' operation would want to note how often a given object is queried.
- A way to tell the whole system the maximum amount of memory to use (ok, that's simple).
The real guts of it would be in the 'put' operation when you hit the memory limit and it has to cull some objects, based on their memory footprint, their costliness, and their usefulness. How do I do that?
Sorry if this is too vague, or off-topic.