Embedded之Stack之三
Stack Overflow
While stacks are generally large, they don't occupy all of memory. It is possible to run out of stack space.
For example, consider the code we had for factorial.
int fact( int n ) {
if ( n == )
return ;
else
return fact( n - ) * n ;
}
Suppose fact(-1) is called. Then, the base case is never reached (well, it might be reached once we decrement so far that n wraps around to 0 again). This causes one stack frame after another to be pushed.
Once the stack limit has been reached, we enter into invalid memory addresses, and the operating system takes over and kills your programming, telling you your program has a stack overflow.
Probably the most common cause of stack overflow is a recursive function that doesn't hit the base case soon enough. For fans of recursion, this can be a problem, so just keep that in mind.
最新文章
- Map拷贝 关于对象深拷贝 浅拷贝的问题
- webapp之meta
- 在Eclipse中生成接口的JUnit测试类
- C#函数参数
- javascript中的真假值、数据类型判断以及+的特殊用法
- 【HDU 5007】Post Robot
- @service中构造方法报错
- Unity3d之Animation(动画系统)
- UCML平台中 如何设置列表单元格中的链接失效
- SQL Server 2008数据库创建,备份,还原图解及注意点
- 既然函数也是对象,那么为什么this不指向普通函数?
- C# FTP下载图片转为Base64
- vue路由详解
- PDF 补丁丁 0.6.0.3383 版发布(修复书签编辑器坐标定位错误的问题)
- ubuntu 安装 eclipse 及其CDT
- redis问题与解决思路
- Python中DataFrame去重
- 全排列问题Ⅱ(Java实现)
- PHP 中如何创建和修改数组?
- java 测试开发基础知识(类加载,JVM等)