这是我的代码
#include<stdio.h> #define ROW 10000 #define COLUMN 10000 void hello(int arr[ROW][COLUMN]){ printf("hoho"); } void main(){ int arr[ROW][COLUMN]; hello(arr); }现在,这给了我分段错误.我的问题是,我知道在进行函数调用时,堆栈用于保存所有传递给函数的变量.那么这是操作系统的堆栈吗?即操作系统是否有专门为此设计的单独内存块?
Now, this gives me segmentation fault. My question is, that I understand that while making a function call, stack is used to keep all the variables passed to the function. So is this the stack of OS? i.e. does OS has a separate memory block designed specially for this?
另外,栈的大小是固定的吗?
Also, is the size of stack fixed?
如果我必须将如此重要的价值传递给我的函数怎么办?
What if I have to pass such great values to my functions?
推荐答案操作系统为其所有任务都有一个单独的堆栈.如果您可以如此轻松地破坏操作系统内存,那将是可怕的.根据您的编译器,您通常有大约 1 MiB 的堆栈内存.如果您需要使用如此大量的内存,请使用 malloc 或 calloc 从堆中分配内存.
The OS has a separate stack for all of its tasks. It would be terrible, if you could corrupt the OS memory so easily. Depending on your compiler, you usually have a bout 1 MiB of stack memory. If you need to use such large amounts of memory, use malloc or calloc for allocating memory from the heap.
编辑
这是 Windows 内存布局的样子.这里是关于此的文章.
This is what Windows memory layout looks like. Here is the article on this.
更多推荐
在 C 中进行函数调用时,是否使用了操作系统的堆栈,堆栈的大小是否固定?
发布评论