Sophie

Sophie

distrib > Mandriva > 9.1 > ppc > by-pkgid > d1f06a5336fd6bf4a381b72b8d2b5ce1 > files > 142

gprolog-1.2.16-3mdk.ppc.rpm

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"
            "http://www.w3.org/TR/REC-html40/loose.dtd">
<HTML>
<HEAD>

<META http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<META name="GENERATOR" content="hevea 1.06-7 of 2001-11-14">
<TITLE>
 Adjusting the size of Prolog stacks
</TITLE>
</HEAD>
<BODY TEXT=black BGCOLOR=white>
<A HREF="manual006.html"><IMG SRC ="previous_motif.gif" ALT="Previous"></A>
<A HREF="manual004.html"><IMG SRC ="contents_motif.gif" ALT="Contents"></A>
<A HREF="manual008.html"><IMG SRC ="next_motif.gif" ALT="Next"></A>
<HR>
<TABLE CELLPADDING=0 CELLSPACING=0 WIDTH="100%">
<TR><TD BGCOLOR="#66dbff"><DIV ALIGN=center><TABLE>
<TR><TD><FONT SIZE=4><B><A NAME="htoc11">3.3</A></B></FONT></TD>
<TD WIDTH="100%" ALIGN=center><FONT SIZE=4><B>Adjusting the size of Prolog stacks</B></FONT></TD>
</TR></TABLE></DIV></TD>
</TR></TABLE>
<A NAME="Adjusting-the-size-of-Prolog-stacks"></A>
GNU Prolog uses several stacks to execute a Prolog program. Each stack has a
static size and cannot be dynamically increased during the execution. For
each stack there is a default size but the user can define a new size by
setting an environment variable. When a GNU Prolog program is run it first
consults these variables and if they are not defined uses the default sizes.
The following table presents each stack of GNU Prolog with its default size
and the name of its associated environment variable:<BR>
<TABLE BORDER=1 CELLSPACING=0 CELLPADDING=1>
<TR><TD ALIGN=center NOWRAP>Stack</TD>
<TD ALIGN=center NOWRAP>Default</TD>
<TD ALIGN=center NOWRAP>Environment</TD>
<TD ALIGN=left NOWRAP>Description</TD>
</TR>
<TR><TD ALIGN=center NOWRAP>name</TD>
<TD ALIGN=center NOWRAP>size (Kb)</TD>
<TD ALIGN=center NOWRAP>variable</TD>
<TD ALIGN=left NOWRAP>&nbsp;</TD>
</TR>
<TR><TD ALIGN=center NOWRAP><TT>local</TT></TD>
<TD ALIGN=center NOWRAP>4096</TD>
<TD ALIGN=center NOWRAP><TT>LOCALSZ</TT></TD>
<TD ALIGN=left NOWRAP>control stack (environments
and choice-points)</TD>
</TR>
<TR><TD ALIGN=center NOWRAP><TT>global</TT></TD>
<TD ALIGN=center NOWRAP>8192</TD>
<TD ALIGN=center NOWRAP><TT>GLOBALSZ</TT></TD>
<TD ALIGN=left NOWRAP>heap (compound terms)</TD>
</TR>
<TR><TD ALIGN=center NOWRAP><TT>trail</TT></TD>
<TD ALIGN=center NOWRAP>3072</TD>
<TD ALIGN=center NOWRAP><TT>TRAILSZ</TT></TD>
<TD ALIGN=left NOWRAP>conditional bindings (bindings
to undo at backtracking)</TD>
</TR>
<TR><TD ALIGN=center NOWRAP><TT>cstr</TT></TD>
<TD ALIGN=center NOWRAP>3072</TD>
<TD ALIGN=center NOWRAP><TT>CSTRSZ</TT></TD>
<TD ALIGN=left NOWRAP>finite domain constraint stack
(FD variables and constraints)</TD>
</TR></TABLE><BR>
If the size of a stack is too small an overflow will occur during the
execution. In that case GNU Prolog emits the following error message before
stopping:
<DL COMPACT=compact><DT><DD><TT><I>S</I> stack overflow (size:&nbsp;<I>N</I> Kb, environment variable used:&nbsp;<I>E</I>)</TT></DL>
where <I><TT>S</TT></I> is the name of the stack, <I><TT>N</TT></I> is
the current stack size in Kb and <I><TT>E</TT></I> the name of the
associated environment variable. When such a message occurs it is possible
to (re)define the variable <I><TT>E</TT></I> with the new size. For
instance to allocate 8192 Kb to the local stack under a Unix shell use:
<DL COMPACT=compact><DT><DD><TABLE CELLSPACING=2 CELLPADDING=0>
<TR><TD ALIGN=left NOWRAP><TT>LOCALSZ=8192; export LOCALS</TT></TD>
<TD VALIGN=top ALIGN=center NOWRAP>&nbsp;&nbsp;</TD>
<TD ALIGN=left NOWRAP>(under <TT>sh</TT> or <TT>bash</TT>)</TD>
</TR>
<TR><TD ALIGN=left NOWRAP><TT>setenv LOCALSZ 8192</TT></TD>
<TD VALIGN=top ALIGN=center NOWRAP>&nbsp;&nbsp;</TD>
<TD ALIGN=left NOWRAP>(under <TT>csh</TT> or <TT>tcsh</TT>)</TD>
</TR></TABLE></DL>
This method allows the user to adjust the size of Prolog stacks. However, in
some cases it is preferable not to allow the user to modify these sizes. For
instance, when providing a stand alone executable whose behavior should be
independent of the environment in which it is run. In that case the program
should not consult environment variables and the programmer should be able
to define new default stack sizes. The GNU Prolog compiler offers this
facilities via several command-line options such as <TT>--local-size</TT> or
<TT>--fixed-sizes</TT> (section&nbsp;<A HREF="manual008.html#Using-the-compiler">3.4.3</A>).<BR>
<BR>
Finally note that GNU Prolog stacks are virtually allocated (i.e. use virtual
memory). This means that a physical memory page is allocated only when needed
(i.e. when an attempt to read/write it occurs). Thus it is possible to define
very large stacks. At the execution, only the needed amount of space will be
physically allocated.<BR>
<BR>

<HR SIZE=2>
Copyright (C) 1999-2002 Daniel Diaz
<BR>
<BR>
Verbatim copying and distribution of this entire article is permitted in any
medium, provided this notice is preserved. <BR>
<BR>
<A HREF="index.html#copyright">More about the copyright</A>
<HR>
<A HREF="manual006.html"><IMG SRC ="previous_motif.gif" ALT="Previous"></A>
<A HREF="manual004.html"><IMG SRC ="contents_motif.gif" ALT="Contents"></A>
<A HREF="manual008.html"><IMG SRC ="next_motif.gif" ALT="Next"></A>
</BODY>
</HTML>