术语“记忆”是什么意思?意味着?

发布于 2024-09-19 07:27:00 字数 376 浏览 10 评论 0原文

比较“memoize”和“cache”这两个术语以及阅读维基百科的 memoization 条目,人们是否同意使用术语“memoize”意味着

  • 记忆结果保存在进程的内存中;换句话说,它不存储在 memcached 中。
  • 一个人只能“记忆”函数,如数学函数,例如斐波那契,而不是可能随时间变化的值,例如网站上注册用户的数量?

如果您正在执行上述以外的其他操作,那么只是缓存结果?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

神经暖 2024-09-26 07:27:32

这是有争议的,因为这些术语可以松散地互换使用。

对我来说,“记忆”的唯一含义是——“缓存”是以前的输入而不是预先计算的表。也就是说——记忆化是一个函数记住它自己的返回值的过程。

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.

烛影斜 2024-09-26 07:27:25

根据我的理解,是的,记忆化就是缓存,用于加速时间必需的程序,例如计算数字序列(例如斐波那契序列)的程序。

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).

天荒地未老 2024-09-26 07:27:19

我相信记忆函数允许您在本地缓存给定参数集的函数结果。它几乎就像:

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;
}

但是最初的巨大“if”块会被自动处理并且效率更高,并且在使用不同参数调用函数时被添加到其中。

请注意,您只能记住确定性且没有副作用的函数。这意味着该函数的结果只能取决于其输入,并且在运行时无法更改任何内容。

简而言之,记忆化是非常特定情况下的函数本地缓存,因此它是常规缓存的特殊化。

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.

只涨不跌 2024-09-26 07:27:13

我不确定,但我的理解是,记忆化要求给定一个函数 y = f(u) ,该 f 是确定性的(也就是说,对于给定的 < code>u,y 必须始终相同),以便可以存储 f 的结果。

对我来说,缓存似乎更多的是确定哪些数据被频繁访问并将这些数据保存在快速存储中的问题。

前者是确定性的,后者是随机性的。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文