gpt4 book ai didi

delphi - FastMM 和动态加载的 DLL

转载 作者:行者123 更新时间:2023-12-03 18:05:02 30 4
gpt4 key购买 nike

我有一个主机应用程序,它在启动时加载了十几个库。我想从 Delphi 7s 默认内存管理器切换到 FastMM4 的完整版本以获得更好的内存泄漏报告。

我应该在主机应用程序和库的使用部分包含 FastMM4 吗?
共享运行时包呢?

一些补充信息:

  • 我们有一个 exe 和 >20 个 dll。每个人都共享一个运行时包。
  • 我们今天不使用 sharemem。不是我所知道的。 ShareMem 不包含在我今天快速浏览的 exe 或 dll 中。

  • 补充问题:
  • 我可以在所有项目的 fastmems inc 文件中使用相同的选项,还是 exe 和 dll 需要不同的设置?
  • 最佳答案

    摘自 FastMM4options.inc文件。

    对我来说,这意味着如果你所有的包、dll 和可执行文件都是用 ShareMM 编译的,那么应该可以替换 Delphi 7s 的默认内存管理器。

    {-----------------------Memory Manager Sharing Options------------------------}

    {Allow sharing of the memory manager between a main application and DLLs that were also compiled with FastMM. This allows you to pass dynamic arrays and long strings to DLL functions provided both are compiled to use FastMM. Sharing will only work if the library that is supposed to share the memory manager was compiled with the "AttemptToUseSharedMM" option set. Note that if the main application is single threaded and the DLL is multi-threaded that you have to set the IsMultiThread variable in the main application to true or it will crash when a thread contention occurs. Note that statically linked DLL files are initialized before the main application, so the main application may well end up sharing a statically loaded DLL's memory manager and not the other way around. }

    {.$define ShareMM}

    {Allow sharing of the memory manager by a DLL with other DLLs (or the main application if this is a statically loaded DLL) that were also compiled with FastMM. Set this option with care in dynamically loaded DLLs, because if the DLL that is sharing its MM is unloaded and any other DLL is still sharing the MM then the application will crash. This setting is only relevant for DLL libraries and requires ShareMM to also be set to have any effect. Sharing will only work if the library that is supposed to share the memory manager was compiled with the "AttemptToUseSharedMM" option set. Note that if DLLs are statically linked then they will be initialized before the main application and then the DLL will in fact share its MM with the main application. This option has no effect unless ShareMM is also set.}

    {.$define ShareMMIfLibrary}

    {Define this to attempt to share the MM of the main application or other loaded DLLs in the same process that were compiled with ShareMM set. When sharing a memory manager, memory leaks caused by the sharer will not be freed automatically. Take into account that statically linked DLLs are initialized before the main application, so set the sharing options accordingly.}

    {.$define AttemptToUseSharedMM}

    {Define this to enable backward compatibility for the memory manager sharing mechanism used by Delphi 2006 and 2007, as well as older FastMM versions.}

    {$define EnableBackwardCompatibleMMSharing}

    关于delphi - FastMM 和动态加载的 DLL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2989289/

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