Interesting. I had never even considered <i>not</i> pre-allocating space for it... :-)<p>In a &quot;real&quot; implementation, you also need space to store sub-capture locations. You get to reuse this space on each execution of the regex, so it&#x27;s a really nice win.<p>There are also certain crazy people in this world who have encoded the NFA algorithm into a code generation tool, which enables it to run completely malloc-free and entirely on the stack. :-)