login

editHow 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.

Enlarge the stacks in Unix

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.