当使用运行时包构建时,如何使我的程序使用更少的内存?
我总是在不使用“使用运行时包构建”的情况下编译我的delphi应用程序,但对于我最新的项目,我必须使用它(因为它开始日益膨胀)。我使用一些第三方VCL(带有源代码的TMS组件包,源代码目录也在搜索路径中),
当我使用运行时包进行编译时,应用程序在运行时使用整个bpl包(否则它只符合内部所需的vcls)包到应用程序中)所以我认为它消耗了很多内存(通常我的应用程序使用 38 Mb 内存,但现在 62 Mb(不仅是 tms,我也使用了许多其他 vcl)根据 Windows 任务管理器)。
有什么方法可以让我的应用程序消耗低内存,就像它被编译为单个 exe 一样。
(我知道只用需要的vcl重新编译VCL包(我有源代码),但是挖掘源代码并找出所需的vcl和子程序太难了)
I always compile my delphi apps without 'build with runtime packages', but for my latest Project i had to use it (as it started swelling day by day ) . I use some third party VCL (TMS component pack with source code , source code directory is in search path also ),
when i compile with build with runtime packages whole bpl package is used by app in runtime (otherwise it complies only the needed vcls inside the package into the app)so i think it consumes much ram memory (normally my app uses 38 Mb ram but now 62 Mb (not only tms i have used many other vcl too )according to windows task manager).
Is there any ways to make my app consume low memory like it was compiled as single exe.
(I know to recompile the VCL packages with only needed vcl (i have the source) but it is too hard for dig the source and find out the needed vcls and sub programs)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我认为你测量的是错误的东西。尽管包文件更大,但这并不一定意味着您的程序占用了更多的 RAM 空间。编译器必须包含包中所有函数和单元的代码,无论任何给定程序使用哪个部分,但这并不意味着所有代码都加载到内存中。操作系统将加载它需要的页面;其余部分将继续驻留在磁盘上的 BPL 文件中。整个 BPL 文件将占用地址空间,但不会加载到物理 RAM 中,因此无需担心,除非您真的面临使用整个 2 GB 地址空间的危险操作系统授予您的进程。
I think you're measuring the wrong thing. Although the package files are bigger, that doesn't necessarily mean your program is occupying more space in RAM. The compiler has to include code for all functions and units in a package, no matter which parts any given program uses, but that doesn't mean that all that code is loaded into memory. The OS will load the pages it needs; the rest will continue to reside on disk, in the BPL file it came from. The whole BPL file will occupy address space, but it won't be loaded into physical RAM, so there's not much to worry about unless you're really in danger of using the entire 2 GB of address space the OS grants your process.
包是DLL,它们需要加载到内存中才能工作。每个包都将包含构建它的所有单元的代码。因此,它们可以使用比使用运行时包构建的 exe 更多的内存 - 尽管您的增加看起来有点太大了。另一方面,如果多个应用程序使用相同的软件包并且它们已正确安装,则它们的代码将被加载到内存中一次。
您可以构建临时包,但您应该非常小心地使用与标准包不同的名称,否则可能会破坏某些其他应用程序,特别是如果您将包放在共享位置或路径中第一个目录中。
在尝试它们之前,我将检查您的应用程序是否未链接未使用的包。 Delphi 将或多或少地放入它所知道的所有包的选项中。您可以在编译后检查哪些包是真正使用的,并将它们仅添加到要使用的包列表中。
Packages are DLLs, they need to be load into memory to work. And each package will contains the code for all the units it is built from. Thereby they can use more memory than an exe built withoyt run-time packages - although your increase looks a bit too large. On the other side, if more than your application use the same packages and they are properly installed, their code will be loaded once into memory.
You could build ad-hoc packages, but you should be very careful to use different names from the standard ones or you could break some other applications, especially if you put your packages in a shared location or in a directory that comes first in the path.
Before trying them, I will check that your application is not linking unused packages. Delphi will put in the options more or less all the packages it knows. You can check after a compile which packages are really used, and add them only to the package list to be used.