1. Computing

Speed and Size: Top 10 Delphi Programming Tricks

By December 21, 2012

Follow me on:

LANGUAGE TIPS :: 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.

Read the full article to learn a few useful tips to make your Delphi programs run faster.


December 27, 2012 at 3:21 pm
(1) Silver Warior says:

I would add few other tips for improving optimization:
1. Never use strings for storing numerical values! Why?
If you have some numerical value stored as string you will need to convert it from string type into actual numerical value before it can be used for some calculations for instance. And later you will need to convert numerical value back into string type to store it. All these conversion takes time.
Storing numerical values in string format is very inefficient as it requires lots more memory to store it. For instance if you want to store integer value of 1000 in string type format you will at least need to use 32 bit of memory (8 bit per character). But if you store it in integer type you can simply use 16 bit integer for it.

December 27, 2012 at 3:22 pm
(2) Silver Warior says:

2. If in you program you use array of some record type where the record itself is quite big (lots of variables), and you need to sort this data you might want to use Objects instead of records in combination with an ObjectList. Why?
When you are sorting data in some array whole blocks of data is being moved back and forth (where size of the block is the size of the array item in a pre mentioned example record). So if you have large array items it will mean that sorting will require lots of data movement and this can become quite slow.
But if you use combination of ObjectList and Object data types sorting of that data won’t require of moving whole data blocks (Objects) but will only move ObjectList items which are actually just pointers to your actual Objects.

December 27, 2012 at 3:22 pm
(3) Silver Warior says:

3. If your program requires large amount of text to work you might consider using word compression on it.
What is word compression do you ask?
Word compression is when you scan your entire text and build a dictionary of used words in that text and then replace those words in the text with Index numbers which represent that word in your dictionary.
This way you can lower the amount of disk space used to store this text quite a lot. If you use 16 bit integer for index you can gain compression for any word with more than two characters in length. Each ANSI character requires 8 bits of data. You can gain even more compression when dealing with Unicode text because each Unicode character requires 12 bits of data.
Word compressed text also offers faster searching capabilities especially when you are searching for whole words. Why? You first do a search in the actual dictionary to see if the word you are searching for is actually present in the text. And if it is present in the text you are then searching for this word appearances using words index which is much faster than searching the occurrence of the first character in the searched word and then checking if all other characters follow.
Searching of partial matches is almost as fast as searching for whole words. But doing partial search which contains part of one word and part of another neighboring word can be much slower.

Leave a Comment

Line and paragraph breaks are automatic. Some HTML allowed: <a href="" title="">, <b>, <i>, <strike>

©2014 About.com. All rights reserved.