Frage

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.

War es hilfreich?

Lösung

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.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top