r2 - 25 Apr 2002 - 08:39:20 - JanWielemakerYou are here: TWiki >  FAQ Web  > EnlargeStacks

How do I enlarge the stacks?

SWI-Prolog's runtime stacks are by default a bit small for demanding programs. The default limit is choosen such that many small programs run just fine and if you make a mistake that makes the stack grow without control it quickly signals this, so you don't have to wait minutes while Prolog is eating all your computers memory.

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

No worries. SWI-Prolog can handle that, but it depends on the platform how to. Continue at the appropriate section.

Enlarging the stacks in Windows

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 (available in the 5.0 versions) 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 Prolog Script 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 Prolog Script
  • 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 32 Mbytes global stack on a default Linux installation:

#!/usr/bin/pl -G32m -s

Stack related commandline options

  • -L<size>[km]
    Specify local stack. Here go environments and choicepoints. Determinism and last-call optimization (tail-recursion) keep it small.

  • -G<size>[km]
    Global stack. Here are compound terms, lists, floats, large integers and strings. Efficient data-structures and determinism keep it small.

  • -T<size>[km]
    Trail stack. Here goes information for rewinding to a choicepoint. Again determinism is a dominant factor to keep it small.

-- JanWielemaker - 17 Apr 2002

Edit | Attach | Printable | Raw View | Backlinks: Web, All Webs | History: r2 < r1 | More topic actions
 
Powered by TWiki
This site is powered by the TWiki collaboration platformCopyright © by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki? Send feedback