在 C 中进行函数调用时,是否使用了操作系统的堆栈,堆栈的大小是否固定?

编程入门 行业动态 更新时间:2024-10-10 21:34:04
本文介绍了在 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 的堆栈内存.如果您需要使用如此大量的内存,请使用 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 中进行函数调用时,是否使用了操作系统的堆栈,堆栈的大小是否固定?

本文发布于:2023-11-29 05:55:54,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1645535.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:堆栈   函数   操作系统   大小   使用了

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!