有没有什么办法来确定在运行时可用堆栈空间? [英] Is there any way to determine the available stack space at run time?

查看:198
本文介绍了有没有什么办法来确定在运行时可用堆栈空间?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道堆栈大小是固定的。因此,我们不能存储堆栈大型物体,我们转移到动态分配(例如malloc的)。此外,当有嵌套函数堆栈被使用要求,所以我们避免递归函数以及这个原因。有什么办法在运行时确定到目前为止有多少堆栈存储器使用,还剩下多少?

I know that stack size is fixed. So we can not store large objects on stack and we shift to dynamic allocations (e.g. malloc). Also, stack gets used when there is nesting of function calls so we avoid recursive functions as well for this reason. Is there any way at runtime to determine how much stack memory is used so far and how much is left ?

在这里,我假设Linux环境(gcc编译器)与x86架构。

Here, I am assuming linux environment (gcc compiler) with x86 architecture.

推荐答案

刚看完%ESP,并记住它的价值下降。你已经知道从环境的默认的最大大小,以及你的线程的起点。

Just read %esp, and remember its value goes down. You already know your defaulted max size from the environment, as well as your threads' starting point.

GCC有很大的装配支持,不像有些片在那里。

gcc has great assembly support, unlike some flakes out there.

这篇关于有没有什么办法来确定在运行时可用堆栈空间?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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