Memory: Stack and Swap
When there isn't enough RAM, dynamically allocated variables on the heap can take advantage of swap space on the disk (albeit causing performance degradations). My question is if the stack in memory can take advantage of the swap space as well.
For example, the following program places a large array on the stack. (Of course, usually we would dynamically allocate large variables on the heap.) If this program crashes when run, can I make it run successfully by adding swap space?
int main()
{
int myArray[1000000];
return 0;
}
Actually it's what swap does, swaps program data and stack space:
http://www.linuxjournal.com/article/10678
These are placed in anonymous pages, so named because they have no named filesystem source. Once modified, an anonymous page must remain in RAM for the duration of the program unless there is secondary storage to write it to. The secondary storage used for these modified anonymous pages is what we call swap space.
The classic recommendation on systems that do strict VM accounting vary, but most of them hover around a “twice the amount of RAM” figure. That number assumes your memory mostly will be filled with a bunch of small interactive programs (where their stack space is possibly their largest memory demand).
Say you're running a Web server with 500 threads, each with 8MB of stack space. That stack space alone is going to require that you have 4GB of swap space configured for the memory accountant to be happy.
链接地址: http://www.djcxy.com/p/14002.html上一篇: 为什么这种记忆食物真的不会记忆?
下一篇: 内存:堆栈和交换