同时使C中的函数调用,使用OS的协议栈,并且是堆栈的大小固定的吗? [英] While making a function call in C, is the stack of OS used, and is the size of stack fixed?

查看:80
本文介绍了同时使C中的函数调用,使用OS的协议栈,并且是堆栈的大小固定的吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下面是我的code

#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);
}

现在,这给了我分段错误。我的问题是,我明白,同时使一个函数调用,堆栈是用来保持传递给函数的所有变量。因此,这是OS的协议栈?即做OS有一个单独的内存块专为这个?

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中的函数调用,使用OS的协议栈,并且是堆栈的大小固定的吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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