| 11 |
.SH "COMPILED PATTERN MEMORY USAGE" |
.SH "COMPILED PATTERN MEMORY USAGE" |
| 12 |
.rs |
.rs |
| 13 |
.sp |
.sp |
| 14 |
Patterns are compiled by PCRE into a reasonably efficient byte code, so that |
Patterns are compiled by PCRE into a reasonably efficient interpretive code, so |
| 15 |
most simple patterns do not use much memory. However, there is one case where |
that most simple patterns do not use much memory. However, there is one case |
| 16 |
the memory usage of a compiled pattern can be unexpectedly large. If a |
where the memory usage of a compiled pattern can be unexpectedly large. If a |
| 17 |
parenthesized subpattern has a quantifier with a minimum greater than 1 and/or |
parenthesized subpattern has a quantifier with a minimum greater than 1 and/or |
| 18 |
a limited maximum, the whole subpattern is repeated in the compiled code. For |
a limited maximum, the whole subpattern is repeated in the compiled code. For |
| 19 |
example, the pattern |
example, the pattern |
| 34 |
.sp |
.sp |
| 35 |
((ab){1,1000}c){1,3} |
((ab){1,1000}c){1,3} |
| 36 |
.sp |
.sp |
| 37 |
uses 51K bytes when compiled. When PCRE is compiled with its default internal |
uses 51K bytes when compiled using the 8-bit library. When PCRE is compiled |
| 38 |
pointer size of two bytes, the size limit on a compiled pattern is 64K, and |
with its default internal pointer size of two bytes, the size limit on a |
| 39 |
this is reached with the above pattern if the outer repetition is increased |
compiled pattern is 64K data units, and this is reached with the above pattern |
| 40 |
from 3 to 4. PCRE can be compiled to use larger internal pointers and thus |
if the outer repetition is increased from 3 to 4. PCRE can be compiled to use |
| 41 |
handle larger compiled patterns, but it is better to try to rewrite your |
larger internal pointers and thus handle larger compiled patterns, but it is |
| 42 |
pattern to use less memory if you can. |
better to try to rewrite your pattern to use less memory if you can. |
| 43 |
.P |
.P |
| 44 |
One way of reducing the memory usage for such patterns is to make use of PCRE's |
One way of reducing the memory usage for such patterns is to make use of PCRE's |
| 45 |
.\" HTML <a href="pcrepattern.html#subpatternsassubroutines"> |
.\" HTML <a href="pcrepattern.html#subpatternsassubroutines"> |
| 68 |
.SH "STACK USAGE AT RUN TIME" |
.SH "STACK USAGE AT RUN TIME" |
| 69 |
.rs |
.rs |
| 70 |
.sp |
.sp |
| 71 |
When \fBpcre_exec()\fP is used for matching, certain kinds of pattern can cause |
When \fBpcre_exec()\fP or \fBpcre16_exec()\fP is used for matching, certain |
| 72 |
it to use large amounts of the process stack. In some environments the default |
kinds of pattern can cause it to use large amounts of the process stack. In |
| 73 |
process stack is quite small, and if it runs out the result is often SIGSEGV. |
some environments the default process stack is quite small, and if it runs out |
| 74 |
This issue is probably the most frequently raised problem with PCRE. Rewriting |
the result is often SIGSEGV. This issue is probably the most frequently raised |
| 75 |
your pattern can often help. The |
problem with PCRE. Rewriting your pattern can often help. The |
| 76 |
.\" HREF |
.\" HREF |
| 77 |
\fBpcrestack\fP |
\fBpcrestack\fP |
| 78 |
.\" |
.\" |
| 101 |
backwards compatibility, and partly for performance reasons. However, you can |
backwards compatibility, and partly for performance reasons. However, you can |
| 102 |
set PCRE_UCP if you want Unicode character properties to be used. This can |
set PCRE_UCP if you want Unicode character properties to be used. This can |
| 103 |
double the matching time for items such as \ed, when matched with |
double the matching time for items such as \ed, when matched with |
| 104 |
\fBpcre_exec()\fP; the performance loss is less with \fBpcre_dfa_exec()\fP, and |
a traditional matching function; the performance loss is less with |
| 105 |
in both cases there is not much difference for \eb. |
a DFA matching function, and in both cases there is not much difference for |
| 106 |
|
\eb. |
| 107 |
.P |
.P |
| 108 |
When a pattern begins with .* not in parentheses, or in parentheses that are |
When a pattern begins with .* not in parentheses, or in parentheses that are |
| 109 |
not the subject of a backreference, and the PCRE_DOTALL option is set, the |
not the subject of a backreference, and the PCRE_DOTALL option is set, the |
| 173 |
.rs |
.rs |
| 174 |
.sp |
.sp |
| 175 |
.nf |
.nf |
| 176 |
Last updated: 16 May 2010 |
Last updated: 09 January 2012 |
| 177 |
Copyright (c) 1997-2010 University of Cambridge. |
Copyright (c) 1997-2012 University of Cambridge. |
| 178 |
.fi |
.fi |