Dismiss Notice

REGISTRATION IS AFTER ADMIN ACTIVATION

DONATIONS WITH PAYPAL CLICK TO BUTTON

1 MONTH VIP - 5$; 3 MONTHS VIP - 10$; 6 MONTHS VIP - 20$; 1 YEAR VIP - 30$; 2 YEARS VIP - 50$; GOLD USER FOR LIFE VIP - 150$

DONATIONS WITH Bitcoin Address:3NRs3CK3fhXifrNYxHEZKpETDd9vNLMsMD

Dismiss Notice
The registration is approved by the Administrator. It takes about 1 day to approve your registration
Dismiss Notice
For open hidden message no need write thanks, thank etc. Enough is click to like button on right side of thread.

Speed and Size: Top 10 Tricks for Delphi

Discussion in 'Delphi Programming' started by N0body, Nov 29, 2013.

  1. N0body
    Online

    N0bodyN0body is a Verified Member DelphiFan Administrator Staff Member DF Staff

    Optimization is one of many desirable goals in software engineering, and is often antagonistic to other important goals such as stability and maintainability.
    In many case the Delphi compiler will take care of the optimization. But that's just limited to aligning the code for pipelines, and some other small tweaks to the code. There is still much to be gained by taking into account how a computer works, and adapting your algorithm to that.

    Here are some of the (unsorted) tips to have in mind while developing Delphi code:

      1. Keep your code clean. This will make it easier to read and understand the code. Use meaningful variable and constant names. For example sMessage, sName for String variables, iCounter for integer variables. Constants could all be uppercase: iRATE for integer constant and sWARNING for a string constant. For components: don't ever use the standard naming: Button1, Edit1, Combo1. The more components you have the more time it'll take to find the one you want.

      2. Leave the {$O+} (or {$Optimization On}) compiler directive on. With this directive, Delphi compiler produces more efficient code. Sometimes, debugging is more difficult with optimization enabled: you cannot set a breakpoint on a statement if the optimizer determines that the statement serves no purpose. All optimizations performed by Delphi's Object Pascal compiler are guaranteed not to alter the meaning of a program.

      3. You may want to compile your programs with run-time packages. This can save a lot on size when you have a lot of programs that use the same libraries. Unfortunately, when distributing your application you will need to deploy dll's as well.

      4. Don't create all the forms on program startup (they are created by default) because this will make your program load slower and require a lot more memory. Instead you should use dynamically created forms.

      5. Use Windows API functions instead of writing your own functions to do the same task. They are usually faster and you will save size too.

      6. When including images in your programs try to optimize them first. When including BMP files be sure that the file has the exact size you need else crop it and make sure that you don't have a 16 color image saved in 64K color mode. When including GIF images you may optimize their color palete with special tools. When including JPEG images you may want to use image compression. Convert JPEG image that contains 256 or less colors to a GIF image - they are much smaller.

      7. When your are going to use only one or two functions or procedures from a unit and you have the unit's source code don't include the whole unit in the uses section but insert only the functions you are going to use into the code. This will prevent Delphi to add to executable all the routines from that unit.

      8. Instead of using non-visible components it's usually better to include the code in your program. There's no need in using a component that displays Windows browse directory dialog when it's really just a few lines of code.

      9. If you have a time-critical function (important loops) you should be very careful. What seems fast on your computer may not be as fast on other PC's. Here you should use as small code as possible and make it fast. You may want to use assembler (always comment it).

      10. Nearly all programs have to do some rudimentary calculations of some kind. Simplifying your formulas to use faster functions is a very typical optimization opportunity. Knowing how data bandwidth and calculations perform relative to each other is also very important. For example, using tables to avoid certain recalculations is often a good idea (values for Sine and Cosine). Always try to use more efficient algorithms to replace an inefficient one are: a Binary Search to replace a Linear Search.
     

Share This Page

Laws
Our website, law, laws, copyright and aims to be respectful of individual rights. Our site, as defined in the law of 5651 serves as a provider of space. According to the law, contrary to the law of site management has no obligation to monitor content. Therefore, our site has adopted the principle of fit and remove. Works are subject to copyright laws and is shared in a manner that violated their legal rights, or professional associations, rights holders who, adsdelphi@gmail.com I can reach us at e-mail address. Complaints considered to be infringing on the examination of the content will be removed from our site.
Donate Help To Us and Be VIP
DONATIONS WITH PAYPAL CLICK TO BUTTON
6 MONTHS VIP - 20$; 1 YEAR VIP - 30$; 2 YEARS VIP - 50$; GOLD USER FOR LIFE VIP - 150$
Social Block