简要说明堆栈框架的概念 [英] Explain the concept of a stack frame in a nutshell

查看:78
本文介绍了简要说明堆栈框架的概念的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在编程语言设计中,我似乎有了调用堆栈的想法。但是我找不到(也许我只是不够努力)关于什么是堆栈框架的解释。

It seems that I get the idea of call stack in programming language design. But I cannot find (probably, I just don't search hard enough) any decent explanation of what stack frame is.

所以我会想让某人用几句话向我解释一下。

So I would like to ask someone to explain it to me in a few words.

推荐答案

堆栈框架是要推送的数据框架到堆栈上。在调用堆栈的情况下,堆栈帧将表示函数调用及其参数数据。

A stack frame is a frame of data that gets pushed onto the stack. In the case of a call stack, a stack frame would represent a function call and its argument data.

如果我没记错的话,函数的返回地址首先被压入堆栈,然后是局部变量的参数和空间。尽管这可能取决于体系结构,但它们共同构成了框架。处理器知道每个帧中有多少字节,并在将帧推入并弹出堆栈时相应地移动堆栈指针。

If I remember correctly, the function return address is pushed onto the stack first, then the arguments and space for local variables. Together, they make the "frame," although this is likely architecture-dependent. The processor knows how many bytes are in each frame and moves the stack pointer accordingly as frames are pushed and popped off the stack.

更高级别的调用堆栈和处理器的调用堆栈之间有很大的区别。

There is a big difference between higher-level call stacks and the processor's call stack.

当我们谈论处理器的调用堆栈时,我们正在讨论在汇编代码或机器代码中使用字节/字级别的地址和值。在谈论高级语言时,有调用栈,但是它们是运行时环境管理的调试/运行时工具,因此您可以(在较高级别)记录程序出了什么问题。在此级别上,通常知道行号,方法和类名之类的东西。到处理器获得代码时,它对这些事情已经一无所知。

When we talk about a processor's call stack, we are talking about working with addresses and values at the byte/word level in assembly or machine code. There are "call stacks" when talking about higher-level languages, but they are a debugging/runtime tool managed by the runtime environment so that you can log what went wrong with your program (at a high level). At this level, things like line numbers and method and class names are often known. By the time the processor gets the code, it has absolutely no concept of these things.

这篇关于简要说明堆栈框架的概念的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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