The intention is to remove the C-stack recursion altogether and use perl's dynamic stacks instead. But that involves quite major surgery to the regexp engine, and I don't know when it is likely to happen.

It does make me wonder whether repetition counts, at least in these fairly simple cases, couldn't be fulfilled with by a tail recursive routine to alleviate the stack growth?

I don't know how you'd implement it to be tail recursive, but feel free to have a go. I suspect you'd need a quite different matching algorithm, in which case you'd probably end up needing rather more surgery than the current plan.

If not, isn't there some scope for putting a check of the form die 'Not enough stack' if reps > stacksize / 792?

As far as I know the stacksize isn't available within the perl process at the moment (nor more relevantly the current free stack space), and the cost per iteration may go up or down (depending on the build). If those numbers can be made available then yes, it would be a good idea to put a check in, probably by treating REG_INFTY as min(32766, freestack/stackcost).

Hugo


In reply to Re^7: What perl operations will consume C stack space? by hv
in thread What perl operations will consume C stack space? by BrowserUk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.