Node:Stack size, Previous:DJGPP specific code, Up:GPC on DJGPP

#### I got an exception when accessing an `array [1 .. 4000000] of Byte`.

Per default, the maximum stack size of a DJGPP application is 256K. If you need more, you have to adjust it with the stubedit program, i.e.:

    stubedit your_app.exe minstack=5000K

Another way is to add the following code to your program to define a minimum stack size (here: 2 MB). This value will be honored even if a user sets a lower value by using stubedit, so this method might be a little safer. (The linker name `_stklen` is essential; the Pascal identifier doesn't matter. The constant doesn't have to be used anywhere in the program. It is recommended to put this declaration in the main program file, not in any unit/module, so programs using a unit/module can set whatever limit they need.)

    {$ifdef __GO32__}
    const
      MinStackSize: Cardinal = $200000; attribute (name = '_stklen');
    {$endif}

Still, it might be a good idea to use pointers for large structures, and allocate the memory at runtime.

DJGPP has to allocate the stack in physical memory at program startup, so one might have to be careful with too large stack limits. Most other systems allocate stack pages on demand, so the only reason to set a limit at all might be to prevent a runaway recursion from eating up all memory ...

On Unix-like systems, you can set a resource limit, but you usually don't do it in normal programs, but rather in the shell settings (bash: `ulimit`; csh: `limit`; syscall: `setrlimit`(2)).