/[pcre]/code/trunk/doc/html/pcrestack.html
ViewVC logotype

Diff of /code/trunk/doc/html/pcrestack.html

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 486 by ph10, Wed Jul 9 11:03:07 2008 UTC revision 487 by ph10, Wed Jan 6 10:26:55 2010 UTC
# Line 31  current call (a "tail recursion"), the f Line 31  current call (a "tail recursion"), the f
31  </P>  </P>
32  <P>  <P>
33  The <b>pcre_dfa_exec()</b> function operates in an entirely different way, and  The <b>pcre_dfa_exec()</b> function operates in an entirely different way, and
34  hardly uses recursion at all. The limit on its complexity is the amount of  uses recursion only when there is a regular expression recursion or subroutine
35  workspace it is given. The comments that follow do NOT apply to  call in the pattern. This includes the processing of assertion and "once-only"
36  <b>pcre_dfa_exec()</b>; they are relevant only for <b>pcre_exec()</b>.  subpatterns, which are handled like subroutine calls. Normally, these are never
37    very deep, and the limit on the complexity of <b>pcre_dfa_exec()</b> is
38    controlled by the amount of workspace it is given. However, it is possible to
39    write patterns with runaway infinite recursions; such patterns will cause
40    <b>pcre_dfa_exec()</b> to run out of stack. At present, there is no protection
41    against this.
42  </P>  </P>
43  <P>  <P>
44  You can set limits on the number of times that <b>match()</b> is called, both in  The comments that follow do NOT apply to <b>pcre_dfa_exec()</b>; they are
45  total and recursively. If the limit is exceeded, an error occurs. For details,  relevant only for <b>pcre_exec()</b>.
 see the  
 <a href="pcreapi.html#extradata">section on extra data for <b>pcre_exec()</b></a>  
 in the  
 <a href="pcreapi.html"><b>pcreapi</b></a>  
 documentation.  
46  </P>  </P>
47    <br><b>
48    Reducing <b>pcre_exec()</b>'s stack usage
49    </b><br>
50  <P>  <P>
51  Each time that <b>match()</b> is actually called recursively, it uses memory  Each time that <b>match()</b> is actually called recursively, it uses memory
52  from the process stack. For certain kinds of pattern and data, very large  from the process stack. For certain kinds of pattern and data, very large
# Line 78  subject strings is to write repeated par Line 81  subject strings is to write repeated par
81  than one character whenever possible.  than one character whenever possible.
82  </P>  </P>
83  <br><b>  <br><b>
84  Compiling PCRE to use heap instead of stack  Compiling PCRE to use heap instead of stack for <b>pcre_exec()</b>
85  </b><br>  </b><br>
86  <P>  <P>
87  In environments where stack memory is constrained, you might want to compile  In environments where stack memory is constrained, you might want to compile
88  PCRE to use heap memory instead of stack for remembering back-up points. This  PCRE to use heap memory instead of stack for remembering back-up points when
89  makes it run a lot more slowly, however. Details of how to do this are given in  <b>pcre_exec()</b> is running. This makes it run a lot more slowly, however.
90  the  Details of how to do this are given in the
91  <a href="pcrebuild.html"><b>pcrebuild</b></a>  <a href="pcrebuild.html"><b>pcrebuild</b></a>
92  documentation. When built in this way, instead of using the stack, PCRE obtains  documentation. When built in this way, instead of using the stack, PCRE obtains
93  and frees memory by calling the functions that are pointed to by the  and frees memory by calling the functions that are pointed to by the
# Line 95  same, and are always freed in reverse or Line 98  same, and are always freed in reverse or
98  customized memory handlers that are more efficient than the standard functions.  customized memory handlers that are more efficient than the standard functions.
99  </P>  </P>
100  <br><b>  <br><b>
101  Limiting PCRE's stack usage  Limiting <b>pcre_exec()</b>'s stack usage
102  </b><br>  </b><br>
103  <P>  <P>
104  PCRE has an internal counter that can be used to limit the depth of recursion,  You can set limits on the number of times that <b>match()</b> is called, both in
105  and thus cause <b>pcre_exec()</b> to give an error code before it runs out of  total and recursively. If a limit is exceeded, <b>pcre_exec()</b> returns an
106  stack. By default, the limit is very large, and unlikely ever to operate. It  error code. Setting suitable limits should prevent it from running out of
107  can be changed when PCRE is built, and it can also be set when  stack. The default values of the limits are very large, and unlikely ever to
108    operate. They can be changed when PCRE is built, and they can also be set when
109  <b>pcre_exec()</b> is called. For details of these interfaces, see the  <b>pcre_exec()</b> is called. For details of these interfaces, see the
110  <a href="pcrebuild.html"><b>pcrebuild</b></a>  <a href="pcrebuild.html"><b>pcrebuild</b></a>
111  and  documentation and the
112    <a href="pcreapi.html#extradata">section on extra data for <b>pcre_exec()</b></a>
113    in the
114  <a href="pcreapi.html"><b>pcreapi</b></a>  <a href="pcreapi.html"><b>pcreapi</b></a>
115  documentation.  documentation.
116  </P>  </P>
# Line 112  documentation. Line 118  documentation.
118  As a very rough rule of thumb, you should reckon on about 500 bytes per  As a very rough rule of thumb, you should reckon on about 500 bytes per
119  recursion. Thus, if you want to limit your stack usage to 8Mb, you  recursion. Thus, if you want to limit your stack usage to 8Mb, you
120  should set the limit at 16000 recursions. A 64Mb stack, on the other hand, can  should set the limit at 16000 recursions. A 64Mb stack, on the other hand, can
121  support around 128000 recursions. The <b>pcretest</b> test program has a command  support around 128000 recursions.
122  line option (<b>-S</b>) that can be used to increase the size of its stack.  </P>
123    <P>
124    In Unix-like environments, the <b>pcretest</b> test program has a command line
125    option (<b>-S</b>) that can be used to increase the size of its stack. As long
126    as the stack is large enough, another option (<b>-M</b>) can be used to find the
127    smallest limits that allow a particular pattern to match a given subject
128    string. This is done by calling <b>pcre_exec()</b> repeatedly with different
129    limits.
130  </P>  </P>
131  <br><b>  <br><b>
132  Changing stack size in Unix-like systems  Changing stack size in Unix-like systems
# Line 163  Cambridge CB2 3QH, England. Line 176  Cambridge CB2 3QH, England.
176  REVISION  REVISION
177  </b><br>  </b><br>
178  <P>  <P>
179  Last updated: 09 July 2008  Last updated: 03 January 2010
180  <br>  <br>
181  Copyright &copy; 1997-2008 University of Cambridge.  Copyright &copy; 1997-2010 University of Cambridge.
182  <br>  <br>
183  <p>  <p>
184  Return to the <a href="index.html">PCRE index page</a>.  Return to the <a href="index.html">PCRE index page</a>.

Legend:
Removed from v.486  
changed lines
  Added in v.487

  ViewVC Help
Powered by ViewVC 1.1.5