2.18 System limits

2.18.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 128 Mbytes on 32 bit processors, or more generally to 2 ** bits-per-long - 5 bytes.

The PrologScript facility described in section 2.10.2.1 provides a mechanism for specifying options with the load-file. On Windows the default stack-sizes are controlled using the Windows registry on the key HKEY_CURRENT_USER\Software\SWI\Prolog using the names localSize, globalSize and trailSize. The value is a DWORD expressing the default stack size in Kbytes. A GUI for modifying these values is provided using the XPCE package. To use this, start the XPCE manual tools using manpce/0, after which you find Preferences in the File menu.

OptionDefaultArea nameDescription
-L 16Mlocal 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 off with the !/0 predicate or no choice points have been created since the invocation and the last subclause is started (last call optimisation).
-G 32Mglobal 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 32Mtrail 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.

In addition, this stack is used by some built-in predicates to handle cyclic terms. Its default size limit is proportional to the global stack limit such that it will never overflow.

Table 2 : Memory areas

2.18.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 up to 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().

2.18.2 Other Limits

Clauses
The only limit on clauses is their arity (the number of arguments to the head), which is limited to 1024. Raising this limit is easy and relatively cheap, removing it is harder.
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.

The number of atoms is limited to 16777216 (16M) on 32-bit machines. On 64-bit machines this is virtually unlimited. See also section 9.6.2.1.

Memory areas
On 32-bit hardware, 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, except for the program heap, which is not limited. On 64-bit hardware there are no meaningful limits.
Nesting of terms
Many build-in predicates process nested terms using recursive C functions. Too deeply nested terms generally cause a fatal crash. All these functions avoid recursion on the right-most argument and therefore terms are not limited on the nesting level of the last argument. This notably covers long lists. Most functions use a stack for correct handling of rational trees (cyclic terms). This stack is segmented, where different segments are allocated using malloc(). Overflow causes a non-graceful exit.
Integers
On most systems SWI-Prolog is compiled with support for unbounded integers by means of the GNU GMP library. In practice this means that integers are bound by the global stack size. Too large integers cause a resource_error. On systems that lack GMP, integers are 64-bit on 32 as well as 64-bit machines.

Integers up to the value of the max_tagged_integer Prolog flag are represented more efficiently on the stack. For clauses and records the difference is much smaller.

Floating point numbers
Floating point numbers are represented as C-native double precision floats, 64 bit IEEE on most machines.

2.18.3 Reserved Names

The boot compiler (see -b option) does not support the module system. 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).