如果CPU的堆栈是1MB,并且编程语言纯粹按值划分,那么我们如何将大于1MB的数据传递到函数中?到底会发生什么?
因此,我听说使用通过值,将参数的副本添加到呼叫堆栈中。显然,Windows上的堆叠尺寸通常为1MB。显然,我们可以轻松地传递远远超过函数/过程之间的1MB的数据(原始图/class/class/hashmaps/sets之类的阵列),
所以我对情况的理解是错误的...还是这些语言是使用通过传递的原始类型的价值,但随后通过对象模型通过参考/传递这些其他数据结构?
只需使用快速的Google,Java& JavaScript专门按值逐渐通过...那么您如何将数据/对象传递到这些语言中的堆栈大小大的数据/对象?例如,在JavaScript中,它说:“对于数组,最大长度为4GB-1(2^32-1)”
So I hear that using pass by value, copies of the parameters are added to the call stack. Apparently, the stack size on Windows is often 1MB. Obviously though, we can easily pass around data that is far bigger than 1MB between functions/procedures (arrays of primitives/classes/hashmaps/sets or whatever)
So is my understanding of the situation wrong...or are these languages using pass by value for primitive types, but then pass by reference/pass by object model for these other data structures?
Just with a quick google, both Java & JavaScript are exclusively pass by value...so how are you able to pass around data/objects bigger than the stack size in these languages? For example, in JavaScript, it's stated: "For Array the maximum length is 4GB-1 (2^32-1)"
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
“逐一转文”和“通过逐个价值”之间的区别在于,在通过通过引用呼叫约定的情况下,该函数可以更改参考点的内容。在不支持通过引用呼叫约定的语言中,您将无法直接执行此操作;您必须通过传递包含对另一个对象的引用的可变类型来模拟它。
在逐个价值中,您也将参考文献作为值传递。因此,当您传递不是原始值的对象时,分配在堆栈上的东西是 pointer 的副本,而不是数据的深副本。
令人困惑的方面是的事物(或实例),您指出的是一种可变的类型,可以突变。
The difference between "pass-by-reference" and "pass-by-value" is that, in pass-by-reference calling convention, the function can change what the reference points to. In languages that don't support a pass-by-reference calling convention, you won't be able to do this directly; you'd have to simulate it by passing a mutable type that contains a reference to another object.
In pass-by-value, you pass references as values too. So the thing that's allocated on the stack, when you're passing an object that isn't a primitive value, is a copy of the pointer, not a deep copy of the data.
The aspect of this that gets confusing is the thing (or instance) of what you point to, if it's a mutable type, can be mutated.