术语“记忆”是什么意思?意味着?
比较“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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
这是有争议的,因为这些术语可以松散地互换使用。
对我来说,“记忆”的唯一含义是——“缓存”是以前的输入而不是预先计算的表。也就是说——记忆化是一个函数记住它自己的返回值的过程。
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.
根据我的理解,是的,记忆化就是缓存,用于加速时间必需的程序,例如计算数字序列(例如斐波那契序列)的程序。
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).
我相信记忆函数允许您在本地缓存给定参数集的函数结果。它几乎就像:
但是最初的巨大“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:
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.
我不确定,但我的理解是,记忆化要求给定一个函数 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)
, thatf
be deterministic (that is, for a givenu
, they
must always be the same), in order that the results off
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.