Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to increase the default stack size beyond 16777216 bytes?

The question says it all. Attempting to increase the stack size in the linker options generates the error :

Maximum Stack Size must be an integer between 65536 and 16777216.

Is this 16MB limit a fundamental limitation of the Delphi compiler or is this an arbitrary limit imposed by the IDE? Is there another way to increase this value?

Note (in anticipation of the comments...) :

  • The need for a larger stack is due to enormous static array types used as local variables
  • I understand that the need to do this is symptomatic of terrible design
  • This is a large legacy application whose design and maintenance I am not responsible for.
  • Refactoring to dynamic arrays works, but incurs a 50% performance penalty.
  • Other refactorings are possible - probably weeks of work. This will likely end up as a side-project.
  • In the meantime, functionality is needed now and a larger stack would be an easy fix.
  • Yes, I really, really know this a bad, bad thing to do.
like image 325
J... Avatar asked Jul 21 '14 12:07

J...


1 Answers

You can increase it as high as 2147483647, using the {$MAXSTACKSIZE} (or {$M minstacksize maxstacksize} compiler directive. Note this is a different use for {$M} than the {$M+/-} used to indicate generation of RTTI for classes.

From the XE6 docwiki (it applied to prior versions as well):

The $M directive specifies an application's stack allocation parameters. minstacksize must be an integer number between 1024 and 2147483647 that specifies the minimum size of an application's stack, and maxstacksize must be an integer number between minstacksize and 2147483647 that specifies the maximum size of an application's stack.

If there is not enough memory available to satisfy an application's minimum stack requirement, Windows will report an error upon attempting to start the application.

like image 147
Ken White Avatar answered Oct 05 '22 05:10

Ken White