Home Contents Index Summary Previous Next

2.13 System Limits

2.13.1 Limits on Memory Areas

SWI-Prolog has a number of memory areas which are only enlarged to a certain limit. The default sizes for these areas should suffice for most applications, but big applications may require larger ones. They are modified by command line options. The table below shows these areas. The first column gives the option name to modify the size of the area. The option character is immediately followed by a number and optionally by a k or m. With k or no unit indicator, the value is interpreted in Kbytes (1024 bytes), with m, the value is interpreted in Mbytes (1024 × 1024 bytes).

The local-, global- and trail-stack are limited to 64 Mbytes on 32 bit processors, or more in general to 2 ** bits-per-long - 6 bytes.

OptionDefaultArea nameDescription
-L 2Mlocal stackThe local stack is used to store the execution environments of procedure invocations. The space for an environment is reclaimed when it fails, exits without leaving choice points, the alternatives are cut of with the !/0 predicate or no choice points have been created since the invocation and the last subclause is started (tail recursion optimisation).
-G 4Mglobal stackThe global stack is used to store terms created during Prolog's execution. Terms on this stack will be reclaimed by backtracking to a point before the term was created or by garbage collection (provided the term is no longer referenced).
-T 4Mtrail stackThe trail stack is used to store assignments during execution. Entries on this stack remain alive until backtracking before the point of creation or the garbage collector determines they are nor needed any longer.
-A 1Margument stackThe argument stack is used to store one of the intermediate code interpreter's registers. The amount of space needed on this stack is determined entirely by the depth in which terms are nested in the clauses that constitute the program. Overflow is most likely when using long strings in a clause.
Table 3 : Memory areas

2.13.1.1 The heap

With the heap, we refer to the memory area used by malloc() and friends. SWI-Prolog uses the area to store atoms, functors, predicates and their clauses, records and other dynamic data. As of SWI-Prolog 2.8.5, no limits are imposed on the addresses returned by malloc() and friends.

On some machines, the runtime stacks described above are allocated using `sparse allocation'. Virtual space upto the limit is claimed at startup and committed and released while the area grows and shrinks. On Win32 platform this is realised using VirtualAlloc() and friends. On Unix systems this is realised using mmap(), either mapping /dev/zero or a temporary file created in /tmp.

As Unix provides no way to reserve part of the address space, this process may lead to conflicts. By default, SWI-Prolog computes the required virtual address space for the runtime stacks. If available, it uses getrlimit() to determine the top of the virtual space reserved for malloc() usage and locates the stacks in the top of this area. It assumes no other mmap() activity such as mapping shared libraries or mmap() by foreign modules will use the area reserved for the heap and malloc(), malloc() will grow the heap from low to high addresses and will notice the existence of the Prolog stacks.

These assumptions appear to hold. The user may using the -H to specify the maximum heap-size. In this case, the Prolog stacks will be allocated at the indicated size from the current top of the heap. On these system, statistics/[0,2] reports heaplimit and heap. The heaplimit value is the distance between the break and the first Prolog stack. The heap value is the distance between what Prolog assumes to be the base of the heap (9) and the current location of the break.

2.13.2 Other Limits

Clauses
Currently the following limitations apply to clauses. The arity may not be more than 1024 and the number of variables should be less than 65536.
Atoms and Strings
SWI-Prolog has no limits on the sizes of atoms and strings. read/1 and its derivatives however normally limit the number of newlines in an atom or string to 5 to improve error detection and recovery. This can be switched off with style_check/1.
Address space
SWI-Prolog data is packed in a 32-bit word, which contains both type and value information. The size of the various memory areas is limited to 128 Mb for each of the areas. With some redesign, the program area could be split into data that should be within this range and the rest of the data, virtually unlimiting the program size.
Integers
Integers are 32-bit to the user, but integers upto the value of the max_tagged_integer feature are represented more efficiently.
Floats
Floating point numbers are represented as native double precision floats, 64 bit IEEE on most machines.

2.13.3 Reserved Names

The boot compiler (see -b option) does not support the module system (yet). As large parts of the system are written in Prolog itself we need some way to avoid name clashes with the user's predicates, database keys, etc. Like Edinburgh C-Prolog Pereira, 1986 all predicates, database keys, etc. that should be hidden from the user start with a dollar ($) sign (see style_check/1).

The compiler uses the special functor $VAR$/1 while analysing the clause to compile. Using this functor in a program causes unpredictable behaviour of the compiler and resulting program.