Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Changing Delphi Thread Size on linecode

Here's my problem:

My current threads are created by default with 1024kb, when I normally need less than 50kb.
Is there a way to parametrize its size by coding? I could only find a way to change it via menu.

Thanks in advance.

like image 248
Filipe.Fonseca Avatar asked Nov 10 '22 12:11

Filipe.Fonseca


1 Answers

It's not possible to specify stack size using TThread. TThread's thread creating code path leads to CreateThread API to be called to use the default stack size for the executable. This is by default 1MB for a Delphi executable (as you have noted). Although you can modify this value (*) through linker options (maximum stack size), or through the corresponding compiler directive, that will have an effect on all threads that use default stack in the application (main, 3rd party TThread, ...).

If you can do without TThread, you can use the BeginThread RTL function to have the StackSize you pass it to be used when you include STACK_SIZE_IS_A_RESERVATION in CreationFlags.

(*) The value that will be reserved for thread stack, Te Waka o Pascal has an article showing effects of using different values.

like image 115
Sertac Akyuz Avatar answered Nov 15 '22 07:11

Sertac Akyuz