## 2.19 System limits

### 2.19.1 Limits on memory areas

The SWI-Prolog engine uses three stacks the local stack (also called environment stack) stores the environment frames used to call predicates as well as choice points. The global stack (also called heap) contains terms, floats, strings and large integers. Finally, the trail stack records variable bindings and assignments to support backtracking. The internal data representation limits these stacks to 128 MB (each) on 32-bit processors. More generally to 2 ** bits-per-pointer - 5 bytes, which implies they are virtually unlimited on 64-bit machines.

As of version 7.7.14, the stacks are restricted by the writeable flag stack_limit or the command line option --stack-limit. This flag limits the combined size of the three stacks per thread. The default limit is currently 512 Mbytes on 32-bit machines, which imposes no additional limit considering the 128 Mbytes hard limit on 32-bit and 1 Gbytes on 64-bit machines.

Considering portability, applications that need to modify the default limits are advised to do so using the Prolog flag stack_limit.

Area name | Description
local stack | The 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).
global stack | The 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).

trail stack

The 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 no longer needed.

As the trail and global stacks are garbage collected together, a small trail can cause an excessive amount of garbage collections. To avoid this, the trail is automatically resized to be at least 1/6th of the size of the global stack.

Table 2 : Memory areas

#### 2.19.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. No limits are imposed on the addresses returned by malloc() and friends.

### 2.19.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 length of atoms and strings. The number of atoms is limited to 16777216 (16M) on 32-bit machines. On 64-bit machines this is virtually unlimited. See also section 12.4.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
  Most built-in predicates that process Prolog terms create an explicitly managed stack and perform optimization for processing the last argument of a term. This implies they can process deeply nested terms at constant and low usage of the C stack, and the system raises a resource error if no more stack can be allocated. Currently only read/1 and write/1 (and all variations thereof) still use the C stack and may cause the system to crash in an uncontrolled way (i.e., not mapped to a Prolog exception that can be caught).
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 integers that appear in clauses, the value (below max_tagged_integer or not) has little impact on the size of the clause.

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

### 2.19.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.