如果我不将它保存在变量中,函数的 return 值存储在内存中的哪里?
Where is the return value of a function stored in memory if I don't save it in a variable?
如果我不将它保存在变量中,函数的 return 值存储在内存中的什么位置,它会保留多长时间?在我使用 return 值后,它会立即被另一个函数或执行覆盖吗?那段内存留了一段时间怎么手动强制覆盖?
调用RunProgram时请注意以下事项...
function GetAValue : Integer;
begin
Result := {some integer value based on other conditions};
end;
procedure RunProgram;
begin
If GetAValue = 362411 then
ShowMessage('Found');
end;
所以当调用 GetAValue 进行上述 "If statement" 比较时...
- 我可以假设它的结果存储在内存中以便能够
比较?
- 我可以假设内存很快就会 overwritten/discarded
因为不再需要它了?
- 如果我希望它被立即丢弃,如何确保它被立即丢弃?
- 调试上述程序的任何人都能够读取该内存吗
比较完成后,可以看到值是多少
在那个阶段 return 是哪个 GetAValue?
这可能取决于优化设置。在 EAX 中返回一个整数值。启用优化后,我希望编译器直接使用 EAX 中返回的值执行比较。禁用优化后,编译器可能会解包到堆栈上的临时本地。您可以检查编译器发出的代码。
寄存器 and/or 堆栈值何时被覆盖取决于此片段周围的代码。
但是这个值谁调试都看得清楚。它在 EAX 寄存器中。它没有存储在命名的 Delphi 变量中这一事实无关紧要。由于代码使用了该值,因此调试器可以看到它。一旦你的程序被调试,你根本无法隐藏任何东西。
为了完整起见,以下是您的要点问题列表的答案:
May I assume that the result of it is stored in memory to be able to compare with?
没有。该值可以存储在寄存器中。
May I assume that that memory will be overwritten/discarded shortly as it will not be needed anymore?
没有。编译器不会写出代码来显式覆盖不再使用的内存。过时的值可能会持续存在。
How do I make sure it is discarded immediately if I wanted it to be?
找出它的存储位置,并覆盖该位置。正如所讨论的,这无济于事。
Will anybody debugging the above program be able to read that memory when the comparison is done and as such be able to see what the value is which GetAValue returned at that stage?
是的。调试器可以看到一切。
如果我不将它保存在变量中,函数的 return 值存储在内存中的什么位置,它会保留多长时间?在我使用 return 值后,它会立即被另一个函数或执行覆盖吗?那段内存留了一段时间怎么手动强制覆盖?
调用RunProgram时请注意以下事项...
function GetAValue : Integer;
begin
Result := {some integer value based on other conditions};
end;
procedure RunProgram;
begin
If GetAValue = 362411 then
ShowMessage('Found');
end;
所以当调用 GetAValue 进行上述 "If statement" 比较时...
- 我可以假设它的结果存储在内存中以便能够 比较?
- 我可以假设内存很快就会 overwritten/discarded 因为不再需要它了?
- 如果我希望它被立即丢弃,如何确保它被立即丢弃?
- 调试上述程序的任何人都能够读取该内存吗 比较完成后,可以看到值是多少 在那个阶段 return 是哪个 GetAValue?
这可能取决于优化设置。在 EAX 中返回一个整数值。启用优化后,我希望编译器直接使用 EAX 中返回的值执行比较。禁用优化后,编译器可能会解包到堆栈上的临时本地。您可以检查编译器发出的代码。
寄存器 and/or 堆栈值何时被覆盖取决于此片段周围的代码。
但是这个值谁调试都看得清楚。它在 EAX 寄存器中。它没有存储在命名的 Delphi 变量中这一事实无关紧要。由于代码使用了该值,因此调试器可以看到它。一旦你的程序被调试,你根本无法隐藏任何东西。
为了完整起见,以下是您的要点问题列表的答案:
May I assume that the result of it is stored in memory to be able to compare with?
没有。该值可以存储在寄存器中。
May I assume that that memory will be overwritten/discarded shortly as it will not be needed anymore?
没有。编译器不会写出代码来显式覆盖不再使用的内存。过时的值可能会持续存在。
How do I make sure it is discarded immediately if I wanted it to be?
找出它的存储位置,并覆盖该位置。正如所讨论的,这无济于事。
Will anybody debugging the above program be able to read that memory when the comparison is done and as such be able to see what the value is which GetAValue returned at that stage?
是的。调试器可以看到一切。