Yuriy Chachora
Yuriy Chachora

Reputation: 769

Why does Firemonkey application use no more than 20% of CPU?

I have a large binary file (700 Mb approximately) which I load to TMemoryStream. After that I perform the reading with TMemoryStream.Read() and make some simple calculations but the application never takes more than 20% of CPU. My PC has i7 processor. Is there any chance to increase the CPU using and speed up the reading process without using the threads?

Upvotes: 3

Views: 1407

Answers (2)

Jerry Dodge
Jerry Dodge

Reputation: 27276

Adding on to Shannon's answer, on an i7 processor with multiple cores, one thread will only be utilizing one core. One thread cannot run on more than one processor core. Therefore, if you wish to utilize multiple cores, you need to create multiple threads to handle various tasks. Creating a thread isn't necessarily as simple as saying do this in that thread, there's a lot to know about multi-threading. For example, your application has one main GUI thread, then one thread might be dedicated for performing some long calculation, another thread might be updating a caption to real-time data, and so on.

Windows automatically decides which core to assign a thread to, and usually divides it up fairly. So, if you have 8 processor cores, and 16 threads, each core would get 2 threads (presumably) and since each core sends its own ticks apart from each other, more than one thread could literally be running at the same time (as opposed to a single core where it divides each 'tick' between each thread).

So to answer your question, if you had 5 threads performing something big at the same time, then you would see 100% processor usage.

Upvotes: 2

Shannon Matthews
Shannon Matthews

Reputation: 10358

As far as I know, the only way to utilise the power of multiple cpu cores with Delphi is to use threads.

If you do choose to use threads in your application, there are a couple libraries that may ease development. How Do I Choose Between the Various Ways to do Threading in Delphi?

Upvotes: 8

Related Questions