| 73 |
stack usage. |
stack usage. |
| 74 |
</P> |
</P> |
| 75 |
<P> |
<P> |
| 76 |
|
This example shows that one way of avoiding stack problems when matching long |
| 77 |
|
subject strings is to write repeated parenthesized subpatterns to match more |
| 78 |
|
than one character whenever possible. |
| 79 |
|
</P> |
| 80 |
|
<P> |
| 81 |
In environments where stack memory is constrained, you might want to compile |
In environments where stack memory is constrained, you might want to compile |
| 82 |
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 |
| 83 |
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 |
| 86 |
documentation. |
documentation. |
| 87 |
</P> |
</P> |
| 88 |
<P> |
<P> |
| 89 |
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 |
| 90 |
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 |
| 91 |
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 |
| 92 |
|
default limit by running the command: |
| 93 |
<pre> |
<pre> |
| 94 |
ulimit -s |
ulimit -s |
| 95 |
</pre> |
</pre> |
| 96 |
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 |
| 97 |
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 |
| 98 |
such as this: |
limit on stack size by code such as this: |
| 99 |
<pre> |
<pre> |
| 100 |
struct rlimit rlim; |
struct rlimit rlim; |
| 101 |
getrlimit(RLIMIT_STACK, &rlim); |
getrlimit(RLIMIT_STACK, &rlim); |
| 122 |
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 |
| 123 |
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 |
| 124 |
support around 128000 recursions. The <b>pcretest</b> test program has a command |
support around 128000 recursions. The <b>pcretest</b> test program has a command |
| 125 |
line option (<b>-S</b>) that can be used to increase its stack. |
line option (<b>-S</b>) that can be used to increase the size of its stack. |
| 126 |
</P> |
</P> |
| 127 |
<P> |
<P> |
| 128 |
Last updated: 29 June 2006 |
Last updated: 14 September 2006 |
| 129 |
<br> |
<br> |
| 130 |
Copyright © 1997-2006 University of Cambridge. |
Copyright © 1997-2006 University of Cambridge. |
| 131 |
<p> |
<p> |