如何查看我的 delphi 应用程序中当前使用了多少堆栈空间? [英] how can i see how much of the stack space is currently used in my delphi app?

查看:25
本文介绍了如何查看我的 delphi 应用程序中当前使用了多少堆栈空间?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何查看我的 delphi 应用程序中当前使用了多少堆栈空间?我遇到了一个非常奇怪的错误,听起来像是堆栈问题.我想将它添加到我的应用程序的日志中,以了解正在使用/剩余的堆栈空间.使用调试器可能不是很好,因为该例程可以被多次调用.

how can i see how much of the stack space is currently used in my delphi app? i had a very strange error that sounds like stack trouble. i'd like to add it to my app's log to get some idea how much stack space is in use/remaining. using the debugger is probably not so great because the routine can be called many times.

谢谢!

推荐答案

{$IFDEF MSWINDOWS}
function currentStackUsage: NativeUInt;
//NB: Win32 uses FS, Win64 uses GS as base for Thread Information Block.
asm
  {$IFDEF WIN32}
  mov eax, fs:[4]  // TIB: base of the stack
  sub eax, esp     // compute difference in EAX (=Result)
  {$ENDIF}
  {$IFDEF WIN64}
  mov rax, gs:[8]  // TIB: base of the stack
  sub rax, rsp     // compute difference in RAX (=Result)
  {$ENDIF}
{$ENDIF}
end;

这篇关于如何查看我的 delphi 应用程序中当前使用了多少堆栈空间?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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