什么是堆栈溢出? [英] What is a stack overflow?

查看:195
本文介绍了什么是堆栈溢出?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

什么是堆栈溢出错误?它可能会以哪种类型的程序/编程语言出现? Web应用程序代码中不太可能发生这种情况?

What is a stack overflow error? What type of programs/programming languages is it likely to occur in? Is it unlikely to occur in web application code?

推荐答案

来自 Wikipedia :

在软件中,发生堆栈溢出 当内存过多时 调用堆栈.在许多编程中 语言,调用堆栈包含一个 有限的内存,通常 在开始时确定 程序.

In software, a stack overflow occurs when too much memory is used on the call stack. In many programming languages, the call stack contains a limited amount of memory, usually determined at the start of the program.

堆栈是一种数据结构,用于记录程序的子例程在完成执行时应将控制权返回给点的记录.当子程序被调用时,返回地址在栈中被 push ,当子例程完成执行时,返回地址被 pull 从栈中拉出.如果有许多子例程,并且堆栈中没有空间,则会发生堆栈溢出.

The stack is a data structure that keeps record of the point the subroutines of a program should return control to when they finish executing. The return addresses are pushed in the stack as the subroutines are being invoked, when the subroutine finish its execution the return address is pulled from the stack. If there are many subroutines and there is no space in the stack a stack overflow happens.

堆栈中还打算存储局部变量,因此,如果局部变量太大,则很有可能堆栈没有空间来存储它,如果是这种情况,也会发生堆栈溢出.

Also in the stack is intended to store local variables so if a local variable is too large is more probable the stack doesn't have space to store it, if this is the case a stack overflow happens too.

Wikipedia包含一个不错的图表,描绘了从另一个名为DrawSquare的子例程中调用DrawLine子例程时的堆栈,希望此图有助于更好地理解堆栈结构.

Wikipedia includes a nice diagram picturing the stack when a DrawLine subroutine is called from another subroutine called DrawSquare, I hope this picture helps to understand better the stack structure.

栈溢出的主要原因有两个:深度函数递归栈变量过大.由于这些是几乎所有编程语言中的通用术语,因此除了语言的复杂性之外,还可能发生堆栈溢出.

There are two main causes of a stack overflow: deep function recursions and excessively large stack variables. Since these are common terms in almost all programming languages a stack overflow can happen besides the complexity of the language.

Guffa 贡献:堆栈与垃圾回收没有任何关系.现代应用程序具有较大的堆栈,这使得堆栈溢出的可能性略有降低,但除此之外没有什么区别.

Guffa contribution: The stack doesn't have anything to do with garbage collection. Modern applications have a larger stack, which makes it slightly less likely to get a stack overflow, but other than that there is no difference.

这篇关于什么是堆栈溢出?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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