堆栈大小在运行时会增长吗?
我想知道堆栈大小是否可以像堆一样在运行时增长?
I wonder if stack size can grow like heap does during runtime?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
我想知道堆栈大小是否可以像堆一样在运行时增长?
I wonder if stack size can grow like heap does during runtime?
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
接受
或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
发布评论
评论(6)
当您分配局部变量和进行函数调用时,使用的堆栈量肯定会增加。堆栈的最大大小是否可以增长在技术上是不确定的,但实际上通常是恒定的。您可以通过操作系统的标志来增大常量,但通常每个线程都会获得一定大小的堆栈。当你使用太多时,就会出现堆栈溢出。
The amount of stack used certainly increases, as you allocate local variables and make function calls. Whether the stack's maximum size can grow is technically undefined, but in practice is generally constant. You can make the constant bigger with a flag to the OS, but usually each thread gets a certain size of stack. When you use too much, it's a stack overflow.
在现代桌面操作系统上,实际分配的堆栈大小可以增长。
实际上它是根据内存管理单元来实现的。当内存被访问超出堆栈的当前提交页面时,新的内存页面将被提交。只有实际使用的页面(通常加上一个保护页面)才会在 RAM 中使用。最大堆栈空间可以通过系统资源限制来控制。例如,在 POSIX.1-2001 上,您可以使用
getrlimit()
查询进程最大堆栈大小。另一方面,旧操作系统和许多嵌入式系统缺乏基于硬件的内存管理单元,确实对堆栈大小设置了固定限制。
The stack size actually allocated can grow on modern desktop operating systems.
In practice it is implemented in terms of the memory management unit. As memory is accessed beyond the current committed pages of the stack, new memory pages are committed in. Only the pages that are actually used (plus one guard page usually) are used in RAM. Maximum stack space can be controlled through system resource limits. For example on POSIX.1-2001 you can query the process maximum stack size with
getrlimit()
.On the other hand, old operating systems and many embedded systems, lacking a hardware-based memory management unit, do set a fixed limit on the stack size.
我认为可执行堆栈大小是由编译器/链接器定义的。因此您可以更改它,但不能在运行时更改。
您可以更改线程的堆栈大小。
+一切都是编译器和操作系统特定的,所以这里没有单一的答案。
I think that the executable stack size is defind by the compiler/linker.. so you can change it but not on runtime.
You can change the stack size of a thread.
+ everything is compiler and os specific, so there is no single answer here.
据我所知,堆栈通常在假设它们存在于连续的内存范围内的情况下进行操作。基本上,期望下一个堆栈帧位于下一位内存中(这有助于它运行得更快,而不必进行指令查找)。就像其他人所说的那样,这是可能的,但我不认为它被广泛使用。
From what I can remember stacks generally operate under the assumption that they exist in a contiguous memory range. Basically the expect the next stack frame to be in the next bit of memory (this helps it run faster not having to do instruction look up). Like others have said it is possible but i don't think it is widely used.
线程的堆栈空间由编译器设置。我的编译器将保留 2Mb 的空间。并将承诺 1 Mb。
当然,您可以更改编译器的默认堆栈大小,也可以通过调用 CreateThread 启动具有更大堆栈大小的新线程。
http://msdn.microsoft.com/en-我们/库/ms682453%28VS.85%29.aspx
A thread's stack space is set by the compiler. My compiler will reserve 2Mb of space. And will commit 1 Mb.
Of course you can change your compilers default stack size, or you can start a new thread with a larger stack size by calling CreateThread.
http://msdn.microsoft.com/en-us/library/ms682453%28VS.85%29.aspx
是的。我认为答案是正确的
yes. i think the answers is true