Visual Prolog Memory Management

Visual Prolog uses the following memory area¡¯s:

Stack     the stack is used for transferring arguments and return addresses for predicate calls. The stack also holds the information for backtrackpoints.

Heap      the heap holds all objects that are more or less permanent, such as database facts, window buffers, file buffers etc.

GStack   the global stack, normally called gstack, is the place where lists, compound structures and strings are placed. The Gstack is only released during backtracking.

Trail       The trail is only used when the program uses reference variables. It holds information about which reference variables must be unbound during backtracking. The trail is allocated in the heap.

1. Releasing Spare Memory Resources

During program execution, the memory is used for several different purposes; depending upon the purpose, spare memory resources can be released in separate ways.

To minimize stack use, avoid unnecessary non-determinism; use the check_determ directive to guide the setting of cuts. Also, take advantage of tail-recursion elimination by writing your predicates so they are tail-recursive.

The global stack is used for building strings and structures. In order to save global stack space, write your program so that the outer loop is a repeat...fail loop.

The trail will seldom be a problem in Visual Prolog. In all versions of Visual Prolog, the trail is dynamically allocated (in the heap), and will be increased in size when necessary. However, in the 16-bit versions the trail is limited to 64K and the first thing to do if the system complains about trail overflow is to avoid using reference domains. If you want to use reference domains, you should decrease the number of backtrack points by using some cuts (use check_determ). The repeat...fail combination will also release the trail. As a last resort, rearrange your predicate calls so that you create less reference variables.

The heap is used when facts are inserted in a database and to store window buffers, file buffers, graphic drivers, database tables, etc. These areas are automatically released when facts are retracted, windows are closed, and so on.