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

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

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

revision 182 by ph10, Wed Jun 13 15:09:54 2007 UTC revision 358 by ph10, Wed Jul 9 11:03:07 2008 UTC
# Line 64  stack usage. Line 64  stack usage.
64  This example shows that one way of avoiding stack problems when matching long  This example shows that one way of avoiding stack problems when matching long
65  subject strings is to write repeated parenthesized subpatterns to match more  subject strings is to write repeated parenthesized subpatterns to match more
66  than one character whenever possible.  than one character whenever possible.
67  .P  .
68    .SS "Compiling PCRE to use heap instead of stack"
69    .rs
70    .sp
71  In environments where stack memory is constrained, you might want to compile  In environments where stack memory is constrained, you might want to compile
72  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
73  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
# Line 79  point to \fBmalloc()\fP and \fBfree()\fP Line 82  point to \fBmalloc()\fP and \fBfree()\fP
82  cause PCRE to use your own functions. Since the block sizes are always the  cause PCRE to use your own functions. Since the block sizes are always the
83  same, and are always freed in reverse order, it may be possible to implement  same, and are always freed in reverse order, it may be possible to implement
84  customized memory handlers that are more efficient than the standard functions.  customized memory handlers that are more efficient than the standard functions.
85    .
86    .SS "Limiting PCRE's stack usage"
87    .rs
88    .sp
89    PCRE has an internal counter that can be used to limit the depth of recursion,
90    and thus cause \fBpcre_exec()\fP to give an error code before it runs out of
91    stack. By default, the limit is very large, and unlikely ever to operate. It
92    can be changed when PCRE is built, and it can also be set when
93    \fBpcre_exec()\fP is called. For details of these interfaces, see the
94    .\" HREF
95    \fBpcrebuild\fP
96    .\"
97    and
98    .\" HREF
99    \fBpcreapi\fP
100    .\"
101    documentation.
102  .P  .P
103    As a very rough rule of thumb, you should reckon on about 500 bytes per
104    recursion. Thus, if you want to limit your stack usage to 8Mb, you
105    should set the limit at 16000 recursions. A 64Mb stack, on the other hand, can
106    support around 128000 recursions. The \fBpcretest\fP test program has a command
107    line option (\fB-S\fP) that can be used to increase the size of its stack.
108    .
109    .SS "Changing stack size in Unix-like systems"
110    .rs
111    .sp
112  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
113  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
114  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 99  limit on stack size by code such as this Line 128  limit on stack size by code such as this
128  This reads the current limits (soft and hard) using \fBgetrlimit()\fP, then  This reads the current limits (soft and hard) using \fBgetrlimit()\fP, then
129  attempts to increase the soft limit to 100Mb using \fBsetrlimit()\fP. You must  attempts to increase the soft limit to 100Mb using \fBsetrlimit()\fP. You must
130  do this before calling \fBpcre_exec()\fP.  do this before calling \fBpcre_exec()\fP.
131  .P  .
132  PCRE has an internal counter that can be used to limit the depth of recursion,  .SS "Changing stack size in Mac OS X"
133  and thus cause \fBpcre_exec()\fP to give an error code before it runs out of  .rs
134  stack. By default, the limit is very large, and unlikely ever to operate. It  .sp
135  can be changed when PCRE is built, and it can also be set when  Using \fBsetrlimit()\fP, as described above, should also work on Mac OS X. It
136  \fBpcre_exec()\fP is called. For details of these interfaces, see the  is also possible to set a stack size when linking a program. There is a
137  .\" HREF  discussion about stack sizes in Mac OS X at this web site:
138  \fBpcrebuild\fP  .\" HTML <a href="http://developer.apple.com/qa/qa2005/qa1419.html">
139  .\"  .\" </a>
140  and  http://developer.apple.com/qa/qa2005/qa1419.html.
 .\" HREF  
 \fBpcreapi\fP  
141  .\"  .\"
 documentation.  
 .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 \fBpcretest\fP test program has a command  
 line option (\fB-S\fP) that can be used to increase the size of its stack.  
142  .  .
143  .  .
144  .SH AUTHOR  .SH AUTHOR
# Line 135  Cambridge CB2 3QH, England. Line 155  Cambridge CB2 3QH, England.
155  .rs  .rs
156  .sp  .sp
157  .nf  .nf
158  Last updated: 05 June 2007  Last updated: 09 July 2008
159  Copyright (c) 1997-2007 University of Cambridge.  Copyright (c) 1997-2008 University of Cambridge.
160  .fi  .fi

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

  ViewVC Help
Powered by ViewVC 1.1.5