Pascal Programming

Entries feed - Comments feed

2011-05-20

How to write fast multi-thread Delphi applications

How to make your software run fast, especially in a multi-threaded architecture?

We tried to remove the Memory Manager scaling problems in our SynScaleMM. It worked as expected in a multi-threaded server environment. Scaling is much better than FastMM4, for some critical tests. But it's not ready for production yet...

To be honest, the Memory Manager is perhaps not the bigger bottleneck in Multi-Threaded applications.

Here are some (not dogmatic, just from experiment and knowledge of low-level Delphi RTL) advice if you want to write FAST multi-threaded application in Delphi.

Continue reading

2011-03-12

TDynArray and Record compare/load/save using fast RTTI

The SynCommons unit has been enhanced:
- new BinToBase64 and Base64ToBin conversion functions;
- new low-level RTTI functions for handling record types: RecordEquals, RecordSave, RecordSaveLength, RecordLoad;
- new TDynArray object, which is a wrapper around any dynamic array.

With TDynArray, you can access any dynamic array (like TIntegerDynArray = array of integer) using TList-like properties and methods, e.g. Count, Add, Insert, Delete, Clear, IndexOf, Find, Sort and some new methods like LoadFromStream, SaveToStream, LoadFrom and SaveTo which allow fast binary serialization of any dynamic array, even containing strings or records - a CreateOrderedIndex method is also available to create individual index according to the dynamic array content. You can also serialize the array content into JSON, if you wish.

What I like with dynamic arrays is that they are reference-counted, don't need any Create/try..finally...Free code, and are well handled by the Delphi compiler.
They are no replacement to a TCollection nor a TList (which are the standard and efficient way of storing class instances), but they are very handy way of having a list of content or a dictionary at hand, with no class nor properties definition.
You can look at them like Python's list, tuples (via records handling) and dictionaries (via Find method), in pure Delphi. Our new methods (about searching and serialization) allow most usage of those script-level structures in your Delphi code.

Continue reading

2011-02-03

TIOBE : Pascal in TOP TEN language

The 2011 TIOBE Index is a gauge that has long tracked the rise and fall of programming languages. First developed during the mid-1990s, the index relies on various data sources to gauge the popularity of languages; that is, the extent to which they're used (but not how much they're liked).

The problem is that it split Delphi and Pascal into two diverse categories. Without this distinction, we would be in the top ten!

Continue reading

2011-01-29

record and object issue in Delphi 2010

In a previous post, I explained why I still like to use, in some special cases, record or object where using a class doesn't perfectly fit my needs.

I just discovered a non reproducing bug in Delphi 2010, about objects: sometimes, reference-counted objects were not initialized!

Continue reading

2010-12-17

Don't weep, take a breath, and maintain

In a message posted in the EMB forum, Anthony wrote that he "inherited this stuff"... Maintaining a Delphi application pays the bills, but... is sometimes frustrating.

Here are some advices or experiment sharing.

Continue reading

2010-12-04

When inlining works

It was told on this Blog that the Delphi memory manager (FastMM4 since Borland 2006 - but it was even worse with the previous "Borland's" MM), doesn't scale well on multi-code CPU. That is, if you have a multi-threaded application with a lot of memory handling (e.g. aString := aString+someString), the Delphi MM won't scale with multi cores. When I mean "don't scale", I mean that the optimistic though of "my CPU has 4 cores, therefore the same work run in 4 threads will be 4 times faster than with 1 thread" is false. It performs even worse with multiple threads than with 1 thread...

So we went into forking a nice project, named ScaleMM, and created our scalable optimized MM, named SynScaleMM. Our forked modifications were even included in the main ScaleMM branch.

During my profiling of our SynScaleMM, I discovered some very nice results with Delphi compiler inlining features.

Continue reading

2010-09-20

Dll hell, WinSXS monster, and Delphi paradise

A funny and honest article on Dr Dobbs told the story of the "DLL hell" on windows.

Writing Delphi applications, in respect to needed libraries to be redistributed along with, is just paradise.

Continue reading

2010-08-14

FPC and Delphi: toward a "fratricidal war"?

Speaking about [upcoming] 64 bit Delphi compiler, I did forecast they will surely release their compiler 5 years later than FPC's... hoping they will follow the FPC way, just as Intel did about 64 bits instructions, against AMD.

What I was referring to is that AMD was the first to publish a 64 bit x86 CPU, with a new instruction set. Intel released somewhat later their own 64 bit x86 CPU, following the same instruction set.
There are some variants between AMD and Intel CPU, some dedicated instructions or implementations.
But most instruction set is perfectly compatible.

And I suspect the more it gets, the less compatible FPC and Delphi will be.

The main difference between Delphi and FPC is that the first is a business company project (Embarcadero), the second an Open Source solution. They are not two billions dollars companies fighting each other, with some state-level institutions watching about any unfair competition or monopoly... FPC compiler is technically a great and robust project, but EMB follows business rules. I don't think anyone will play "Anti-monopoly" in favor of FPC.

Continue reading

2010-08-10

Writing Delphi code for 64 bits compiler

There will be an upcoming 64 bits Delphi compiler. Embarcadero promised it.

Florian (the architect of FPC) showed a first "Hello world" program for Win64 in March 2006.
This was remarkable since GCC and the binutils don't even support this target at this time.
In fact, FPC used its Internal linker on Win32 and Win64 platforms, just like Delphi does.

Here are some points on how you could make your code ready to compile under FPC 64 bits, therefore (I hope) under future Delphi 64 bits compiler.

Continue reading

2010-08-07

Every Delphi DB program contains hidden code for EMB license checking

After looking further at the SysUtils unit, I found out some small piece of asm code I didn't notice at first.

There is some hidden and not documented code in every program using the DB features, in order to verify that you have the right to use some drivers or DB features.

The license checking performed by Borland (it was a trick existing in Delphi 4, or perhaps before) is somewhat childish.

Continue reading

2010-08-06

Save object, stop class hegemony!

In a recent thread in the Embarcadero Discussion Forums, Vedran Vuk posted some questions about object keyword.
His purpose was to use object instead of class to improve speed and memory consumption: 

I do use classes. I just want to use objects on smaller classes that don't really need initialization or RTTI. Plus, I can directly operate on it like a record with no need for constructors and it can be sealed and has inheritance. Every byte matters in this case.

Rudy posted on the EMB forum that

The "object" type is deprecated. As was said, it mainly exists for compatibility with old Turbo Pascal. That is why it is not documented very well. It's use is not promoted.

I have the same requirement sometimes, for example for our framework or for low-level units.
I do like such plain-old object type, and don't want to see this object feature marked as deprecated in future EMB versions.

Continue reading

2010-07-30

Compiler enhancement proposal: threadlocalvar

As I wrote in a previous post, Delphi string, dynamic array and memory manager don't like multi-core CPU.

My proposal is to add a threadlocalvar keyword, to be used instead of var in your code, to mark some variables to be used in only the current thread. Then the compiler and RTL won't have to use the LOCK instruction, and the application will be MUCH faster in multi-thread environment.

Continue reading

2010-07-24

Damnatio Memoriae

You sure heard about the "CrossKylixGate"... A Great tool I used for years (CrossKylix) has just been updated. Its author (named Simon) posted an announcement in the Embarcadero forums. Then the post has been deleted by "Team B" members, because of some old story.

But not only Simon has been censured. Since I like and use this free tool, I posted a very "soft" post just with the announcement of the CrossKylix update, with some explanations and precisions. No debate. Just a link to the download page. Then my whole thread was deleted.

It just sounds like a "damnatio memoriae" to me.

Continue reading

2010-07-23

Unit Testing light in Delphi

Automated Unit Testing is a great improvement in coding safe applications.

If you don't know about it, visit http://xprogramming.com/index.php then come back here, and you'll discover how we implement unit testing in a KISS way, in pure Delphi code.

Continue reading

2010-07-15

Delphi doesn't like multi-core CPUs (or the contrary)

If you're like me, you are proud of the new CPU your computer runs on - in my case a i7-720Q with 8 embedded cores...

But Delphi is not very multi-thread or multi-core friendly... guess why....

Continue reading

2010-07-04

Named Pipe, Vista, Seven and Service

If you want some local communicate between a service software and a front-end GUI application, named pipes are a viable mechanism for this communication. It worked fine until Windows XP, then came Vista, Seven, and the UAC...

Continue reading

2010-07-02

JSON format of a RESTful application

RESTful JSON is still a buzzing process... there is no standard yet, and they should not be, since JSON itself has its own RFC, and REST is a powerful but vague statement.

Continue reading

2010-06-30

Why do I stay on Delphi 7?

I'm still using Delphi 7 as my favorite IDE.

Continue reading

2010-03-28

Mac OS X Stack Alignment, asm and trolls

In a very interesting commentPhiS spoke about the Mac OS X Stack Alignment problem, and the way asm code should be written for the future Cross Platform Delphi compiler. Here are some (hope without any Troll hidden) reflections I went through.

Continue reading

page 4 of 4 -