version 1.1.1.1, 2012/02/21 23:05:52
|
version 1.1.1.3, 2013/07/22 08:25:57
|
Line 24 of them.
|
Line 24 of them.
|
COMPILED PATTERN MEMORY USAGE |
COMPILED PATTERN MEMORY USAGE |
</b><br> |
</b><br> |
<P> |
<P> |
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 |
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 |
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 |
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 |
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 |
example, the pattern |
example, the pattern |
Line 48 example, the very simple pattern
|
Line 48 example, the very simple pattern
|
<pre> |
<pre> |
((ab){1,1000}c){1,3} |
((ab){1,1000}c){1,3} |
</pre> |
</pre> |
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 |
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 |
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 |
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 |
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 |
pattern to use less memory if you can. | better to try to rewrite your pattern to use less memory if you can. |
</P> |
</P> |
<P> |
<P> |
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 |
Line 77 that PCRE cannot otherwise handle.
|
Line 77 that PCRE cannot otherwise handle.
|
STACK USAGE AT RUN TIME |
STACK USAGE AT RUN TIME |
</b><br> |
</b><br> |
<P> |
<P> |
When <b>pcre_exec()</b> is used for matching, certain kinds of pattern can cause | When <b>pcre_exec()</b> or <b>pcre[16|32]_exec()</b> is used for matching, certain |
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 |
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 |
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 |
your pattern can often help. The | problem with PCRE. Rewriting your pattern can often help. The |
<a href="pcrestack.html"><b>pcrestack</b></a> |
<a href="pcrestack.html"><b>pcrestack</b></a> |
documentation discusses this issue in detail. |
documentation discusses this issue in detail. |
</P> |
</P> |
Line 99 contains a few observations about PCRE.
|
Line 99 contains a few observations about PCRE.
|
</P> |
</P> |
<P> |
<P> |
Using Unicode character properties (the \p, \P, and \X escapes) is slow, |
Using Unicode character properties (the \p, \P, and \X escapes) is slow, |
because PCRE has to scan a structure that contains data for over fifteen | because PCRE has to use a multi-stage table lookup whenever it needs a |
thousand characters whenever it needs a character's property. If you can find | character's property. If you can find an alternative pattern that does not use |
an alternative pattern that does not use character properties, it will probably | character properties, it will probably be faster. |
be faster. | |
</P> |
</P> |
<P> |
<P> |
By default, the escape sequences \b, \d, \s, and \w, and the POSIX |
By default, the escape sequences \b, \d, \s, and \w, and the POSIX |
Line 110 character classes such as [:alpha:] do not use Unicode
|
Line 109 character classes such as [:alpha:] do not use Unicode
|
backwards compatibility, and partly for performance reasons. However, you can |
backwards compatibility, and partly for performance reasons. However, you can |
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 |
double the matching time for items such as \d, when matched with |
double the matching time for items such as \d, when matched with |
<b>pcre_exec()</b>; the performance loss is less with <b>pcre_dfa_exec()</b>, and | a traditional matching function; the performance loss is less with |
in both cases there is not much difference for \b. | a DFA matching function, and in both cases there is not much difference for |
| \b. |
</P> |
</P> |
<P> |
<P> |
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 |
Line 186 Cambridge CB2 3QH, England.
|
Line 186 Cambridge CB2 3QH, England.
|
REVISION |
REVISION |
</b><br> |
</b><br> |
<P> |
<P> |
Last updated: 16 May 2010 | Last updated: 25 August 2012 |
<br> |
<br> |
Copyright © 1997-2010 University of Cambridge. | Copyright © 1997-2012 University of Cambridge. |
<br> |
<br> |
<p> |
<p> |
Return to the <a href="index.html">PCRE index page</a>. |
Return to the <a href="index.html">PCRE index page</a>. |