Get access to over 100 FireMonkey cross platform samples for Android, IOS, OSX, Windows, and Linux!

AndroidAppmethodCode SnippetComponentDelphiDemoFiremonkeyIOSOSXWindows

Parallel Processing Loop With Delphi XE5 Firemonkey On Android And IOS

Delphi XE5 Firemonkey Parallel Processing LoopI found an example over on StackOverflow showing how to do a parallel processing loop using Delphi XE5 Firemonkey. On dual and quad core devices it will create a thread for each CPU and then using a for loop it will process each iteration of the loop in a different thread using an anonymous method. Theoretically you could achieve a performance gain by using parallel processing in this fashion. However, the comments under the code on StackOverflow also point out some performance flaws with this method including that it does not use pooled threads. I had to tweak the original code just a bit to get it working cross platform. It runs on Windows and Android now (and probably IOS and OSX). I have included a demo application which shows the usage of the parallel loop. I also included the Android thread patch in the demo if you need to use a TBitmap in the loop.

The demo takes a TMemo with some text in it and places the text in two different TMemo components depending on which thread is running the loop. The ThreadId that places it in the new memo is prepended to the text string. I included support in the demo for up to 24 threads as I figured that should cover most multicore CPUs for awhile. It also does some meaningless work in the threads (with Random()) to slow down the loop. Here is the example of using the ParallelFor() loop from the demo:

Download the Parallel Processing Loop Demo and TParallel unit.

Head over and read the full question and answer on StackOverflow about the parallel loop.

close

Have Delphi Firemonkey questions? Ask and get answers on StackOverflow.

Related posts
AndroidC++BuilderDelphiFiremonkeyIOSOSXWindows

FireMonkey 10.4.2 Features Updated iOS 14, Android 11, And macOS 11 Support Plus Hundreds Of Fixes

DelphiIDEShowcaseWindows

Ryzen 9 5950x: One Billion Lines Of Delphi Code Compiled In ~5 Minutes On 16 Cores

DelphiFiremonkeyIDEIOSOSXWindows

DelphiCon 2020 FireMonkey Sessions Available Starting November 19

AndroidC++BuilderDelphiDemoFiremonkeyWindows

Powerful Commercial Gorilla3D Framework Upgraded For Delphi FireMonkey On Windows And Android

Sign up for our Newsletter and
stay informed

Leave a Reply