• No results found

System limits

In document AINN ICT4101 FS (Page 61-64)

on these errors can be controlled using set stream/2. Initially the terminal stream writes the characters using Prolog escape sequences while other streams generate an I/O exception.

BOM: Byte Order Mark

From section2.18.1, you may have got the impression that text files are complicated. This section deals with a related topic, making life often easier for the user, but providing another worry to the programmer. BOMorByte Order Markeris a technique for identifying Unicode text files as well as the encoding they use. Such files start with the Unicode character 0xFEFF, a non-breaking, zero-width space character. This is a pretty unique sequence that is not likely to be the start of a non-Unicode file and uniquely distinguishes the various Unicode file formats. As it is a zero-width blank, it even doesn’t produce any output. This solves all problems, or . . .

Some formats start off as US-ASCII and may contain some encoding mark to switch to UTF-8, such as theencoding="UTF-8"in an XML header. Such formats often explicitly forbid the use of a UTF-8 BOM. In other cases there is additional information revealing the encoding, making the use of a BOM redundant or even illegal.

The BOM is handled by SWI-Prologopen/4predicate. By default, text files are probed for the BOM when opened for reading. If a BOM is found, the encoding is set accordingly and the property bom(true) is available throughstream property/2. When opening a file for writing, writing a BOM can be requested using the optionbom(true) withopen/4.

2.19

System limits

2.19.1 Limits on memory areas

SWI-Prolog has a number of memory areas which are only enlarged to a certain limit. The internal data representation limits the local, global and trail stack to 128 MB on 32-bit processors, or more generally to 2bits-per-pointer−5 bytes. Considering that almost all modern hardware can deal with this amount of memory with ease, the default limits are set to their maximum on 32-bit hardware. The representation limits can easily exceed physical memory on 64-bit hardware. The default limits on 64-bit hardware are double that of 32-bit hardware, which allows for storing the same amount of (Prolog) data.

The limits can be changed from the command line as well as at runtime using set prolog stack/2. 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 akorm. Withkor no unit indicator, the value is interpreted in Kbytes (1024 bytes); withm, the value is interpreted in Mbytes (1024×1024bytes).

The PrologScript facility described in section2.10.2provides 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, globalSizeandtrailSize. The value is aDWORDexpressing 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 usingmanpce/0, after which you findPreferencesin theFilemenu.

Considering portability, applications that need to modify the default limits are advised to do so usingset prolog stack/2.

Option Default Area name Description

-L 128M local stack The local stack is used to store the execution environments of procedure invocations. The space for an environment is re- claimed when it fails, exits with- out leaving choice points, the al- ternatives are cut off with the !/0 predicate or no choice points have been created since the invo- cation and the last subclause is started (last call optimisation). -G 128M global stack The global stack is used to store

terms created during Prolog’s execution. Terms on this stack will be reclaimed by backtrack- ing to a point before the term was created or by garbage col- lection (provided the term is no longer referenced).

-T 128M trail stack The trail stack is used to store as- signments during execution. En- tries on this stack remain alive until backtracking before the point of creation or the garbage collector determines they are no longer needed.

2.19. SYSTEM LIMITS 61

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 sizes of atoms and strings. read/1and its derivatives, however, normally limit the number of newlines in an atom or string to 6 to improve error detection and recovery. This can be switched off withstyle 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 section11.4.2.

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 onlyread/1andwrite/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 aresource 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 integeror 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 -boption) does not support the module system. As large parts of the sys- tem 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.

In document AINN ICT4101 FS (Page 61-64)