/[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 1193 by ph10, Sat Jan 21 16:37:17 2012 UTC revision 1194 by ph10, Wed Oct 31 17:42:29 2012 UTC
# Line 16  man page, in case the conversion went wr Line 16  man page, in case the conversion went wr
16  PCRE DISCUSSION OF STACK USAGE  PCRE DISCUSSION OF STACK USAGE
17  </b><br>  </b><br>
18  <P>  <P>
19  When you call <b>pcre[16]_exec()</b>, it makes use of an internal function  When you call <b>pcre[16|32]_exec()</b>, it makes use of an internal function
20  called <b>match()</b>. This calls itself recursively at branch points in the  called <b>match()</b>. This calls itself recursively at branch points in the
21  pattern, in order to remember the state of the match so that it can back up and  pattern, in order to remember the state of the match so that it can back up and
22  try a different alternative if the first one fails. As matching proceeds deeper  try a different alternative if the first one fails. As matching proceeds deeper
# Line 33  the recursive call would immediately be Line 33  the recursive call would immediately be
33  current call (a "tail recursion"), the function is just restarted instead.  current call (a "tail recursion"), the function is just restarted instead.
34  </P>  </P>
35  <P>  <P>
36  The above comments apply when <b>pcre[16]_exec()</b> is run in its normal  The above comments apply when <b>pcre[16|32]_exec()</b> is run in its normal
37  interpretive manner. If the pattern was studied with the  interpretive manner. If the pattern was studied with the
38  PCRE_STUDY_JIT_COMPILE option, and just-in-time compiling was successful, and  PCRE_STUDY_JIT_COMPILE option, and just-in-time compiling was successful, and
39  the options passed to <b>pcre[16]_exec()</b> were not incompatible, the matching  the options passed to <b>pcre[16|32]_exec()</b> were not incompatible, the matching
40  process uses the JIT-compiled code instead of the <b>match()</b> function. In  process uses the JIT-compiled code instead of the <b>match()</b> function. In
41  this case, the memory requirements are handled entirely differently. See the  this case, the memory requirements are handled entirely differently. See the
42  <a href="pcrejit.html"><b>pcrejit</b></a>  <a href="pcrejit.html"><b>pcrejit</b></a>
43  documentation for details.  documentation for details.
44  </P>  </P>
45  <P>  <P>
46  The <b>pcre[16]_dfa_exec()</b> function operates in an entirely different way,  The <b>pcre[16|32]_dfa_exec()</b> function operates in an entirely different way,
47  and uses recursion only when there is a regular expression recursion or  and uses recursion only when there is a regular expression recursion or
48  subroutine call in the pattern. This includes the processing of assertion and  subroutine call in the pattern. This includes the processing of assertion and
49  "once-only" subpatterns, which are handled like subroutine calls. Normally,  "once-only" subpatterns, which are handled like subroutine calls. Normally,
50  these are never very deep, and the limit on the complexity of  these are never very deep, and the limit on the complexity of
51  <b>pcre[16]_dfa_exec()</b> is controlled by the amount of workspace it is given.  <b>pcre[16|32]_dfa_exec()</b> is controlled by the amount of workspace it is given.
52  However, it is possible to write patterns with runaway infinite recursions;  However, it is possible to write patterns with runaway infinite recursions;
53  such patterns will cause <b>pcre[16]_dfa_exec()</b> to run out of stack. At  such patterns will cause <b>pcre[16|32]_dfa_exec()</b> to run out of stack. At
54  present, there is no protection against this.  present, there is no protection against this.
55  </P>  </P>
56  <P>  <P>
57  The comments that follow do NOT apply to <b>pcre[16]_dfa_exec()</b>; they are  The comments that follow do NOT apply to <b>pcre[16|32]_dfa_exec()</b>; they are
58  relevant only for <b>pcre[16]_exec()</b> without the JIT optimization.  relevant only for <b>pcre[16|32]_exec()</b> without the JIT optimization.
59  </P>  </P>
60  <br><b>  <br><b>
61  Reducing <b>pcre[16]_exec()</b>'s stack usage  Reducing <b>pcre[16|32]_exec()</b>'s stack usage
62  </b><br>  </b><br>
63  <P>  <P>
64  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
# Line 94  subject strings is to write repeated par Line 94  subject strings is to write repeated par
94  than one character whenever possible.  than one character whenever possible.
95  </P>  </P>
96  <br><b>  <br><b>
97  Compiling PCRE to use heap instead of stack for <b>pcre[16]_exec()</b>  Compiling PCRE to use heap instead of stack for <b>pcre[16|32]_exec()</b>
98  </b><br>  </b><br>
99  <P>  <P>
100  In environments where stack memory is constrained, you might want to compile  In environments where stack memory is constrained, you might want to compile
101  PCRE to use heap memory instead of stack for remembering back-up points when  PCRE to use heap memory instead of stack for remembering back-up points when
102  <b>pcre[16]_exec()</b> is running. This makes it run a lot more slowly, however.  <b>pcre[16|32]_exec()</b> is running. This makes it run a lot more slowly, however.
103  Details of how to do this are given in the  Details of how to do this are given in the
104  <a href="pcrebuild.html"><b>pcrebuild</b></a>  <a href="pcrebuild.html"><b>pcrebuild</b></a>
105  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
106  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
107  <b>pcre[16]_stack_malloc</b> and <b>pcre[16]_stack_free</b> variables. By  <b>pcre[16|32]_stack_malloc</b> and <b>pcre[16|32]_stack_free</b> variables. By
108  default, these point to <b>malloc()</b> and <b>free()</b>, but you can replace  default, these point to <b>malloc()</b> and <b>free()</b>, but you can replace
109  the pointers to cause PCRE to use your own functions. Since the block sizes are  the pointers to cause PCRE to use your own functions. Since the block sizes are
110  always the same, and are always freed in reverse order, it may be possible to  always the same, and are always freed in reverse order, it may be possible to
# Line 112  implement customized memory handlers tha Line 112  implement customized memory handlers tha
112  functions.  functions.
113  </P>  </P>
114  <br><b>  <br><b>
115  Limiting <b>pcre[16]_exec()</b>'s stack usage  Limiting <b>pcre[16|32]_exec()</b>'s stack usage
116  </b><br>  </b><br>
117  <P>  <P>
118  You can set limits on the number of times that <b>match()</b> is called, both in  You can set limits on the number of times that <b>match()</b> is called, both in
119  total and recursively. If a limit is exceeded, <b>pcre[16]_exec()</b> returns an  total and recursively. If a limit is exceeded, <b>pcre[16|32]_exec()</b> returns an
120  error code. Setting suitable limits should prevent it from running out of  error code. Setting suitable limits should prevent it from running out of
121  stack. The default values of the limits are very large, and unlikely ever to  stack. The default values of the limits are very large, and unlikely ever to
122  operate. They can be changed when PCRE is built, and they can also be set when  operate. They can be changed when PCRE is built, and they can also be set when
123  <b>pcre[16]_exec()</b> is called. For details of these interfaces, see the  <b>pcre[16|32]_exec()</b> is called. For details of these interfaces, see the
124  <a href="pcrebuild.html"><b>pcrebuild</b></a>  <a href="pcrebuild.html"><b>pcrebuild</b></a>
125  documentation and the  documentation and the
126  <a href="pcreapi.html#extradata">section on extra data for <b>pcre[16]_exec()</b></a>  <a href="pcreapi.html#extradata">section on extra data for <b>pcre[16|32]_exec()</b></a>
127  in the  in the
128  <a href="pcreapi.html"><b>pcreapi</b></a>  <a href="pcreapi.html"><b>pcreapi</b></a>
129  documentation.  documentation.
# Line 139  In Unix-like environments, the <b>pcrete Line 139  In Unix-like environments, the <b>pcrete
139  option (<b>-S</b>) that can be used to increase the size of its stack. As long  option (<b>-S</b>) that can be used to increase the size of its stack. As long
140  as the stack is large enough, another option (<b>-M</b>) can be used to find the  as the stack is large enough, another option (<b>-M</b>) can be used to find the
141  smallest limits that allow a particular pattern to match a given subject  smallest limits that allow a particular pattern to match a given subject
142  string. This is done by calling <b>pcre[16]_exec()</b> repeatedly with different  string. This is done by calling <b>pcre[16|32]_exec()</b> repeatedly with different
143  limits.  limits.
144  </P>  </P>
145  <br><b>  <br><b>
# Line 190  limit on stack size by code such as this Line 190  limit on stack size by code such as this
190  </pre>  </pre>
191  This reads the current limits (soft and hard) using <b>getrlimit()</b>, then  This reads the current limits (soft and hard) using <b>getrlimit()</b>, then
192  attempts to increase the soft limit to 100Mb using <b>setrlimit()</b>. You must  attempts to increase the soft limit to 100Mb using <b>setrlimit()</b>. You must
193  do this before calling <b>pcre[16]_exec()</b>.  do this before calling <b>pcre[16|32]_exec()</b>.
194  </P>  </P>
195  <br><b>  <br><b>
196  Changing stack size in Mac OS X  Changing stack size in Mac OS X
# Line 216  Cambridge CB2 3QH, England. Line 216  Cambridge CB2 3QH, England.
216  REVISION  REVISION
217  </b><br>  </b><br>
218  <P>  <P>
219  Last updated: 21 January 2012  Last updated: 24 June 2012
220  <br>  <br>
221  Copyright &copy; 1997-2012 University of Cambridge.  Copyright &copy; 1997-2012 University of Cambridge.
222  <br>  <br>

Legend:
Removed from v.1193  
changed lines
  Added in v.1194

  ViewVC Help
Powered by ViewVC 1.1.5