gpt4 book ai didi

c++ - MASM 本地人 : dynamically allocated data?

转载 作者:搜寻专家 更新时间:2023-10-31 01:53:49 27 4
gpt4 key购买 nike

我正在按照一些教程学习 masm32。在一个教程中:http://win32assembly.online.fr/tut3.html有说明:

LOCAL directive allocates memory from the stack for local variables used in the function. The bunch of LOCAL directives must be immediately below the PROC directive. The LOCAL directive is immediately followed by :. So LOCAL wc:WNDCLASSEX tells MASM to allocate memory from the stack the size of WNDCLASSEX structure for the variable named wc. We can refer to wc in our codes without any difficulty involved in stack manipulation. That's really a godsend, I think. The downside is that local variables cannot be used outside the function they're created and will be automatically destroyed when the function returns to the caller. Another drawback is that you cannot initialize local variables automatically because they're just stack memory allocated dynamically when the function is entered . You have to manually assign them with desired values after LOCAL directives.

我一直被告知堆栈内存是静态的,而任何动态分配都是堆内存。那么我们真的可以将它们视为 C++ 意义上的局部变量吗?当您在 C++ 中创建局部变量时,这些变量是否也会在堆栈上动态分配?

最佳答案

Can we really consider those as locals in the sense of C++ then? When you create local variables in C++, will those variables be dynamically allocated on the stack as well?

在 C++ 中,局部(自动)变量存在于堆栈中,所以是的,是的。

它们是动态分配的,因为它们随着函数的进入/退出而来来去去。但是,正如您正确指出的那样,这种类型的分配与堆分配有很大不同。

除了堆和栈之外,还有第三个区域可以驻留变量。它是数据段。这是全局以及函数级和类级 static 变量所在的位置。

关于c++ - MASM 本地人 : dynamically allocated data?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10590891/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com