/[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 93 by nigel, Sat Feb 24 21:41:42 2007 UTC revision 358 by ph10, Wed Jul 9 11:03:07 2008 UTC
# Line 63  frame for each matched character. For a Line 63  frame for each matched character. For a
63  required. Consider now this rewritten pattern, which matches exactly the same  required. Consider now this rewritten pattern, which matches exactly the same
64  strings:  strings:
65  <pre>  <pre>
66    ([^&#60;]++|&#60;(?!inet))    ([^&#60;]++|&#60;(?!inet))+
67  </pre>  </pre>
68  This uses very much less stack, because runs of characters that do not contain  This uses very much less stack, because runs of characters that do not contain
69  "&#60;" are "swallowed" in one item inside the parentheses. Recursion happens only  "&#60;" are "swallowed" in one item inside the parentheses. Recursion happens only
# Line 77  This example shows that one way of avoid Line 77  This example shows that one way of avoid
77  subject strings is to write repeated parenthesized subpatterns to match more  subject strings is to write repeated parenthesized subpatterns to match more
78  than one character whenever possible.  than one character whenever possible.
79  </P>  </P>
80    <br><b>
81    Compiling PCRE to use heap instead of stack
82    </b><br>
83  <P>  <P>
84  In environments where stack memory is constrained, you might want to compile  In environments where stack memory is constrained, you might want to compile
85  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. This
86  makes it run a lot more slowly, however. Details of how to do this are given in  makes it run a lot more slowly, however. Details of how to do this are given in
87  the  the
88  <a href="pcrebuild.html"><b>pcrebuild</b></a>  <a href="pcrebuild.html"><b>pcrebuild</b></a>
89    documentation. When built in this way, instead of using the stack, PCRE obtains
90    and frees memory by calling the functions that are pointed to by the
91    <b>pcre_stack_malloc</b> and <b>pcre_stack_free</b> variables. By default, these
92    point to <b>malloc()</b> and <b>free()</b>, but you can replace the pointers to
93    cause PCRE to use your own functions. Since the block sizes are always the
94    same, and are always freed in reverse order, it may be possible to implement
95    customized memory handlers that are more efficient than the standard functions.
96    </P>
97    <br><b>
98    Limiting PCRE's stack usage
99    </b><br>
100    <P>
101    PCRE has an internal counter that can be used to limit the depth of recursion,
102    and thus cause <b>pcre_exec()</b> to give an error code before it runs out of
103    stack. By default, the limit is very large, and unlikely ever to operate. It
104    can be changed when PCRE is built, and it can also be set when
105    <b>pcre_exec()</b> is called. For details of these interfaces, see the
106    <a href="pcrebuild.html"><b>pcrebuild</b></a>
107    and
108    <a href="pcreapi.html"><b>pcreapi</b></a>
109  documentation.  documentation.
110  </P>  </P>
111  <P>  <P>
112    As a very rough rule of thumb, you should reckon on about 500 bytes per
113    recursion. Thus, if you want to limit your stack usage to 8Mb, you
114    should set the limit at 16000 recursions. A 64Mb stack, on the other hand, can
115    support around 128000 recursions. The <b>pcretest</b> test program has a command
116    line option (<b>-S</b>) that can be used to increase the size of its stack.
117    </P>
118    <br><b>
119    Changing stack size in Unix-like systems
120    </b><br>
121    <P>
122  In Unix-like environments, there is not often a problem with the stack unless  In Unix-like environments, there is not often a problem with the stack unless
123  very long strings are involved, though the default limit on stack size varies  very long strings are involved, though the default limit on stack size varies
124  from system to system. Values from 8Mb to 64Mb are common. You can find your  from system to system. Values from 8Mb to 64Mb are common. You can find your
# Line 106  This reads the current limits (soft and Line 139  This reads the current limits (soft and
139  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
140  do this before calling <b>pcre_exec()</b>.  do this before calling <b>pcre_exec()</b>.
141  </P>  </P>
142    <br><b>
143    Changing stack size in Mac OS X
144    </b><br>
145    <P>
146    Using <b>setrlimit()</b>, as described above, should also work on Mac OS X. It
147    is also possible to set a stack size when linking a program. There is a
148    discussion about stack sizes in Mac OS X at this web site:
149    <a href="http://developer.apple.com/qa/qa2005/qa1419.html">http://developer.apple.com/qa/qa2005/qa1419.html.</a>
150    </P>
151    <br><b>
152    AUTHOR
153    </b><br>
154  <P>  <P>
155  PCRE has an internal counter that can be used to limit the depth of recursion,  Philip Hazel
156  and thus cause <b>pcre_exec()</b> to give an error code before it runs out of  <br>
157  stack. By default, the limit is very large, and unlikely ever to operate. It  University Computing Service
158  can be changed when PCRE is built, and it can also be set when  <br>
159  <b>pcre_exec()</b> is called. For details of these interfaces, see the  Cambridge CB2 3QH, England.
160  <a href="pcrebuild.html"><b>pcrebuild</b></a>  <br>
 and  
 <a href="pcreapi.html"><b>pcreapi</b></a>  
 documentation.  
 </P>  
 <P>  
 As a very rough rule of thumb, you should reckon on about 500 bytes per  
 recursion. Thus, if you want to limit your stack usage to 8Mb, you  
 should set the limit at 16000 recursions. A 64Mb stack, on the other hand, can  
 support around 128000 recursions. The <b>pcretest</b> test program has a command  
 line option (<b>-S</b>) that can be used to increase the size of its stack.  
161  </P>  </P>
162    <br><b>
163    REVISION
164    </b><br>
165  <P>  <P>
166  Last updated: 14 September 2006  Last updated: 09 July 2008
167    <br>
168    Copyright &copy; 1997-2008 University of Cambridge.
169  <br>  <br>
 Copyright &copy; 1997-2006 University of Cambridge.  
170  <p>  <p>
171  Return to the <a href="index.html">PCRE index page</a>.  Return to the <a href="index.html">PCRE index page</a>.
172  </p>  </p>

Legend:
Removed from v.93  
changed lines
  Added in v.358

  ViewVC Help
Powered by ViewVC 1.1.5