什么简单的变化使您的Delphi程序最大的改进 [英] What Simple Changes Made the Biggest Improvements to Your Delphi Programs

查看:88
本文介绍了什么简单的变化使您的Delphi程序最大的改进的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Delphi 2009程序,可以处理大量的数据,并且需要尽可能的快,不要使用太多的内存。

I have a Delphi 2009 program that handles a lot of data and needs to be as fast as possible and not use too much memory.

什么小简单的更改您是否通过明显减少执行时间或内存使用对您的程序性能造成最大影响的Delphi代码?

What small simple changes have you made to your Delphi code that had the biggest impact on the performance of your program by noticeably reducing execution time or memory use?

感谢大家所有的答案。许多很好的提示。

Thanks everyone for all your answers. Many great tips.

为了完整,我将发布一些关于我发现的Delphi优化的重要文章。

For completeness, I'll post a few important articles on Delphi optimization that I found.

在开始优化Delphi代码之前在About.com上

Before you start optimizing Delphi code at About.com

速度和大小:顶关于About.com的10个技巧

代码优化基础知识高性能德尔福的Delphi优化指南,涉及Delphi 7但仍然非常相关。

Code Optimization Fundamentals and Delphi Optimization Guidelines at High Performance Delp relating to Delphi 7 but still very pertinent.

推荐答案

当我开始使用AsyncCalls来转换以前用于冻结UI,进入(排序)多重广告应用程序。

The biggest improvement came when I started using AsyncCalls to convert single-threaded applications that used to freeze up the UI, into (sort of) multi-threaded apps.

虽然AsyncCalls可以做得更多,但我发现它对这个非常简单的目的很有用。假设你有一个这样的子程序:禁用按钮,做工作,启用按钮。
将做工作部分移动到本地函数(称为AsyncDoWork),并添加四行代码:

Although AsyncCalls can do a lot more, I've found it useful for this very simple purpose. Let's say you have a subroutine blocked like this: Disable Button, Do Work, Enable Button. You move the 'Do Work' part to a local function (call it AsyncDoWork), and add four lines of code:

var  a: IAsyncCall;    
a := LocalAsyncCall(@AsyncDoWork);  
while (NOT a.Finished) do 
  application.ProcessMessages;  
a.Sync;

这对您来说是一个单独的线程运行AsyncDoWork,而主线程仍然可以响应到UI(如拖动窗口或单击中止)。当AsyncDoWork完成后,代码将继续。因为我把它移动到一个本地的函数,所有本地的var可用,代码不需要改变。

What this does for you is run AsyncDoWork in a separate thread, while your main thread remains available to respond to the UI (like dragging the window or clicking Abort.) When AsyncDoWork is finished the code continues. Because I moved it to a local function, all local vars are available, an the code does not need to be changed.

这是一个非常有限的线程。具体来说,它是双线程。您必须确保您的Async功能和UI不会同时访问相同的VCL组件或数据结构。 (我禁用除停止按钮之外的所有控件。)

This is a very limited type of 'multi-threading'. Specifically, it's dual threading. You must ensure that your Async function and the UI do not both access the same VCL components or data structures. (I disable all controls except the stop button.)

我不用这样写新的程序。这只是一个非常快速的简单的方法使旧程序更加敏感。

I don't use this to write new programs. It's just a really quick & easy way to make old programs more responsive.

这篇关于什么简单的变化使您的Delphi程序最大的改进的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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