views:

92

answers:

4

Comparing the terms "memoize" and "cache" and in reading Wikipedia's memoization entry, do people agree that using the term "memoize" implies

  • The memoized result is kept in the process' memory; in other words, it isn't stored in memcached .
  • One only "memoizes" functions, as in mathematical functions, e.g. Fibonacci, not values that may change over time, e.g. the number of registered users on the web site?

If you're doing anything else than the above, then one is just caching a result?

+1  A: 

From my understanding, yes, memoization is caching, used to speed up a time-essential program such as one that calculates a number sequence (e.g. Fibonacci sequence).

Delan Azabani
Yes, is it caching, but does memoizing imply a specific case of caching where the result is only stored in memory and it only caches a function.
Blair Zajac
Like Blair said, memoization is a kind of caching. You can cache things without it being memoization but not the other way around.
Andrew Hubbs
Ah, I see now. So memoization is a specific type of caching.
Delan Azabani
+2  A: 

I believe that memoizing a function allows you to locally cache the result of a function for a given set of arguments. It's almost like:

function f(a, b, c) {
  if (a==1 && b==2 && !c) {
    return 5;
  } else if (a==1 && b==3 && !c) {
    return 17.2;
  } /* ... etc ... */

  // some horribly long/complex/expensive calculation
  return result;
}

but with the initial huge "if" block being handled automatically and far more efficiently, and being added to as the function is called with different arguments.

Note that you can only memoize a function that is deterministic and has no side effects. This means that the function's result can only depend on its inputs, and it cannot change anything when it is run.

So in short, memoization is function-local caching in very specific circumstances, and so it's a specialisation of regular caching.

Dave
That is totally not how I understand it - here you have simply provided function logic to handle cases. The whole point of memoizing is that the input is not known, but once it has been entered then the function memorises it so it would only do "some horribly long/complex/expensive calculation" once...
Fraser
+4  A: 

I'm not sure, but my understanding is that memoization requires that given a function y = f(u), that f be deterministic (that is, for a given u, the y must always be the same), in order that the results of f may be stored.

Caching to me seems to be more of a problem of determining what pieces of data are accessed frequently, and keeping those data in fast storage.

The former is deterministic while the latter is stochastic.

Gilead
+1  A: 

It is debatable as the terms can loosely be used interchangeably.

To me the sole implication of 'memoize' would be - That the 'caching' is of previous inputs rather than precomputed tables. That is - memoization is a process of a function to remember its own return values.

Fraser