5

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.

1
  • 4
    You can specify the stack size if you use BeginThread, with the appropriate CreationFlags. Feb 21, 2014 at 13:51

1 Answer 1

1

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.