在 C 中进行函数调用时,是否使用了操作系统的堆栈,堆栈的大小是否固定? [英] While making a function call in C, is the stack of OS used, and is the size of stack fixed?

查看:19
本文介绍了在 C 中进行函数调用时,是否使用了操作系统的堆栈,堆栈的大小是否固定?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的代码

#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 的堆栈内存.如果您需要使用如此大量的内存,请使用 malloccalloc 从堆中分配内存.

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 中进行函数调用时,是否使用了操作系统的堆栈,堆栈的大小是否固定?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆