问题描述
我已阅读到Linux上的标准"和初始堆栈大小为〜8MB,而Windows为〜1MB.
I have read that the "standard" and initial stack size on Linux is ~8MB and Windows is ~1MB.
但是堆分配如何工作?操作系统是否像为已提交和保留的内存的堆栈那样为进程堆设置虚拟"大小?
But how does the heap allocation work? Does the OS set a "virtual" size to the process heap like it does for the stack with committed and reserved memory?
推荐答案
通常,程序的布局在内存低端具有'text'(或'code')段,后跟固定数据('数据"和"bss"段),然后是一个间隙,堆栈从高内存向下增长.中间的间隙成为堆,堆从数据的末尾向堆栈增长.
Classically, the layout of a program has the 'text' (or 'code') segment at the low end of memory, followed by the fixed data ('data' and 'bss' segments), followed by a gap, with the stack growing downwards from high memory. The gap in the middle becomes the heap, which grows from the end of the data towards the stack.
线程程序,加载的共享库,共享的内存等使事情变得更加复杂.
Things are more complex with threaded programs, shared libraries loaded, shared memory, etc.
初始堆栈大小取决于o/s.初始堆大小在逻辑上为零,但趋于几乎立即增长(随着程序和共享库的加载).
The initial stack size is o/s dependent. The initial heap size is logically zero, but tends to grow almost immediately (as the program and the shared libraries are loaded).
这篇关于什么是“标准"? C程序中堆栈和堆的大小?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!