How do I enlarge the stacks?
Old versions of SWI-Prolog had quite limited default stack-sizes. As of version 5.10.0, there are no resources involved with unused spack-space and the limits on 32-bit platforms are by default the maximum that can be handled on these platforms: 128Mb. On 64-bit platforms the default is 256Mb, which typically means you have the same limit as on 32-bit systems. However, on 64-bit platforms you can extend the limits.
But, my program is too big. What now?
Prune choicepoints. Deterministic programs use way less memory on all the stacks. Use the SWI-Prolog source-level debugger to find choicepoints.
But I really have a lot of choicepoints and data
SWI-Prolog can handle that on 64-bit systems. As of version 5.10.0, the limits can be modified at runtime using set_prolog_stack/2. In addition, the mechanisms below can be used. Continue at the appropriate section.
Enlarging the stacks in Windows without using set_prolog_stack/2
In windows you have several options.
- Using a .BAT file you can provide the appropiate options.
- You can modify the shortcut from menu or desktop to include the options.
- You can open Preferences/Stack sizes from the plwin.exe menu and specify new limits. These limits are stored in the Windows registry and are the default for any new Prolog instance you start.
- You can use the PrologScript magic sequence, which is handled for a Prolog file you open using double-click just as the Unix version does, except that the path to the executable is ignored (but some path must be specified).
Enlarge the stacks in Unix
- Use a shell script
- Use a PrologScript
- Use command-line options
Specifying stack-sizes using Prolog Script
Make sure your file starts with #!, followed by location of Prolog, followed by options you want to pass and ending with the -s (script) option. Here is an example using 4Gbytes global stack on a default Linux installation:
#!/usr/bin/swipl -G4g -s
Stack related commandline options
Stack sizes are specified in Kbytes (k, default), Mbytes (using m postfix) or Gbytes (using g postfix).
- -L<size>[kmg]
- Specify local stack. Here go environments and choicepoints. Determinism and last-call optimization (tail-recursion) keep it small.
- -G<size>[kmg]
- Global stack. Here are compound terms, lists, floats, large integers and strings. Efficient data-structures and determinism keep it small.
- -T<size>[kmg]
- Trail stack. Here goes information for rewinding to a choicepoint. Again determinism is a dominant factor to keep it small.