George Reilly wrote:
> With MSVCRT, you can use _resetstkoflw() in an exception handler to deal
> with stack overflows:
> vclrf_resetstkoflw.asp. However, it's much easier to handle allocation
> failures from malloc(). Also, _resetstkoflow() may not be available on other
> Win32 compilers, such as Borland or Ming32.
We first need to be able to catch the stack overflow. But this sounds a
bit complicated. It would be much easier if we can check how much stack
space is left, so that we can abort the regexp code when we are running
out. For Unix this is done with get_stack_limit() in os_unix.c.
> By default, the stack size is 1MB. This can be adjusted by the /STACK option
> to the linker. Or adjusted after the fact with EDITBIN.
This only helps to make the problem appear in less situations, it's not
a useful fix.
> The stack is not the right resource for huge allocations; the heap is. If
> _alloca() really makes a noticeable difference for the common case, I'd
> suggest some kind of hybrid scheme where you allocate the first few thousand
> bytes from the stack and fall back on the heap thereafter.
I know, I know. The regexp code was written to do recursive calls.
Thus it's a matter of very many small allocations. Rewriting it to
allocate memory with malloc() instead would be a huge task.
hundred-and-one symptoms of being an internet addict:
237. You tattoo your email address on your forehead.
/// Bram Moolenaar -- Bram@...
/// Creator of Vim - Vi IMproved -- http://www.vim.org
\\\ Project leader for A-A-P -- http://www.a-a-p.org
\\\ Lord Of The Rings helps Uganda - http://iccf-holland.org/lotr.html