/[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 91 by nigel, Sat Feb 24 21:41:34 2007 UTC revision 182 by ph10, Wed Jun 13 15:09:54 2007 UTC
# Line 52  frame for each matched character. For a Line 52  frame for each matched character. For a
52  required. Consider now this rewritten pattern, which matches exactly the same  required. Consider now this rewritten pattern, which matches exactly the same
53  strings:  strings:
54  .sp  .sp
55    ([^<]++|<(?!inet))    ([^<]++|<(?!inet))+
56  .sp  .sp
57  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
58  "<" are "swallowed" in one item inside the parentheses. Recursion happens only  "<" are "swallowed" in one item inside the parentheses. Recursion happens only
# Line 61  assume this is relatively rare). A posse Line 61  assume this is relatively rare). A posse
61  backtracking into the runs of non-"<" characters, but that is not related to  backtracking into the runs of non-"<" characters, but that is not related to
62  stack usage.  stack usage.
63  .P  .P
64    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
66    than one character whenever possible.
67    .P
68  In environments where stack memory is constrained, you might want to compile  In environments where stack memory is constrained, you might want to compile
69  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
70  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 68  the Line 72  the
72  .\" HREF  .\" HREF
73  \fBpcrebuild\fP  \fBpcrebuild\fP
74  .\"  .\"
75  documentation.  documentation. When built in this way, instead of using the stack, PCRE obtains
76    and frees memory by calling the functions that are pointed to by the
77    \fBpcre_stack_malloc\fP and \fBpcre_stack_free\fP variables. By default, these
78    point to \fBmalloc()\fP and \fBfree()\fP, but you can replace the pointers to
79    cause PCRE to use your own functions. Since the block sizes are always the
80    same, and are always freed in reverse order, it may be possible to implement
81    customized memory handlers that are more efficient than the standard functions.
82  .P  .P
83  In Unix-like environments, there is not often a problem with the stack, though  In Unix-like environments, there is not often a problem with the stack unless
84  the default limit on stack size varies from system to system. Values from 8Mb  very long strings are involved, though the default limit on stack size varies
85  to 64Mb are common. You can find your default limit by running the command:  from system to system. Values from 8Mb to 64Mb are common. You can find your
86    default limit by running the command:
87  .sp  .sp
88    ulimit -s    ulimit -s
89  .sp  .sp
90  The effect of running out of stack is often SIGSEGV, though sometimes an error  Unfortunately, the effect of running out of stack is often SIGSEGV, though
91  message is given. You can normally increase the limit on stack size by code  sometimes a more explicit error message is given. You can normally increase the
92  such as this:  limit on stack size by code such as this:
93  .sp  .sp
94    struct rlimit rlim;    struct rlimit rlim;
95    getrlimit(RLIMIT_STACK, &rlim);    getrlimit(RLIMIT_STACK, &rlim);
# Line 107  As a very rough rule of thumb, you shoul Line 118  As a very rough rule of thumb, you shoul
118  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
119  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
120  support around 128000 recursions. The \fBpcretest\fP test program has a command  support around 128000 recursions. The \fBpcretest\fP test program has a command
121  line option (\fB-S\fP) that can be used to increase its stack.  line option (\fB-S\fP) that can be used to increase the size of its stack.
122  .P  .
123  .in 0  .
124  Last updated: 29 June 2006  .SH AUTHOR
125  .br  .rs
126  Copyright (c) 1997-2006 University of Cambridge.  .sp
127    .nf
128    Philip Hazel
129    University Computing Service
130    Cambridge CB2 3QH, England.
131    .fi
132    .
133    .
134    .SH REVISION
135    .rs
136    .sp
137    .nf
138    Last updated: 05 June 2007
139    Copyright (c) 1997-2007 University of Cambridge.
140    .fi

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

  ViewVC Help
Powered by ViewVC 1.1.5