gpt4 book ai didi

actionscript-3 - 在 ActionScript Bytecode 中,NewActivation 是什么意思?

转载 作者:行者123 更新时间:2023-12-04 04:29:57 26 4
gpt4 key购买 nike

有些方法使用它有些不使用,显然这是由needsActivation 标志指定的,它有什么作用,何时使用,何时不使用?

AVM 文档上的信息有点不慷慨:

创建一个新的激活对象 newactivation 并将其压入堆栈。只能用于在 MethodInfo 条目中设置了 NEED_ACTIVATION 标志的方法中。

最佳答案

AVM 2 概述的第 6.3 节中有一个很好的描述:

Since the local registers of an activation are not captured when the newfunction instruction is executed, the environment for non-leaf functions must be stored in activation objects that can be captured properly. The newactivation instruction creates such an activation.



当它内部定义了局部函数时,它会在方法中使用,例如:
public function QuickTest()
{
startTimer(1);
startTimer(2);
}

public function startTimer(id:int):void
{
var timer:Timer = new Timer(1000, 1);
timer.addEventListener(TimerEvent.TIMER_COMPLETE, function(ev:TimerEvent):void
{
trace('Timer #'+id+' done.');
});
timer.start();
}

结果是:
Timer #1 done.
Timer #2 done.

您可以看到调用方法时局部变量和参数被“锁定”。这是因为 startTimer 方法在每次运行时都会创建一个激活,这是这些变量被锁定的地方。如果未锁定局部变量,则此代码的结果将是:
Timer #2 done.
Timer #2 done.

关于actionscript-3 - 在 ActionScript Bytecode 中,NewActivation 是什么意思?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5399792/

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